Skip to main content
Participating Frequently
Nov 15, 2021 1:38 PM UTC

Curl using BPXBATCH

I have Conda installed and am using /etc/profile for the environment variables for Conda.  I'm trying to execute curl in batch but not having much luck.  I'm using the following JCL.

//CURL EXEC PGM=BPXBATCH
//STDOUT DD SYSOUT=*
//STDERR DD SYSOUT=*
//STDENV DD PATH='/etc/profile',PATHOPTS=ORDONLY
//STDIN DD DUMMY
//STDPARM DD *
sh 'curl --version'
/*

I keep getting "-bash: curl --version: command not found"  

It's not finding the environment variables (PATH, MANPATH, etc).

This works:

//CURL EXEC PGM=BPXBATCH
//STDOUT DD SYSOUT=*
//STDERR DD SYSOUT=*
//STDENV DD PATH='/etc/profile',PATHOPTS=ORDONLY
//STDIN DD DUMMY
//STDPARM DD *
sh '/rsusr/conda/envs/default/bin/curl' --version
/*

What's the magic secret handshake/decoder ring to get curl to execute in batch?  No, I don't want to issue the "conda activate default" command, I want it to use the /etc/profile environment variables I already have set up.



------------------------------
Michael Babcock
z/OS Systems Programmer, Sr
OneMain Financial
Evansville IN US
------------------------------

    11 replies

    Participating Frequently
    Nov 17, 2021 5:04 PM UTC
    When bash is run under BPXBATCH, it starts in non-interactive mode. Per the official doc, it only executes /etc/profile when run in interactive mode or when the --login (-l) key is specified. The latter probably explains why the script from Michael's last message works fine.

    Here's the doc:

    https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html


    To cut it short: when 'Program' in OMVS is set to bash, the file /etc/profile is not executed; when it's sh, both /etc/profile and $HOME/.profile are executed. And this is normal, documented behavior of bash, not something specific to z/OS.

    There are multiple ways to work around this. For example, you can use the BASH_ENV variable (described at the above page) to make it run /etc/profile. Something like this:

    //STDENV DD *
    BASH_ENV=/etc/profile
    /*

    This worked fine for me.

    Another option would be to set OMVS shell to sh, but then execute the script explicitly via bash. This should work with sh:

    //STDPARM DD *
    sh /bin/bash -c "curl --version"
    /*

    Or you could specify bash in the shebang, if you're running a script and not just curl.

    #!/bin/bash
    curl --version

    Which way to choose, much depends on exactly what you need.

    Regards,
    Vladimir

    ------------------------------
    Vladimir Ein
    ------------------------------
    And then there is the sledgehammer approach.
    In the early days, before getting a slightly better understanding of shells, I used a batch TSO step to build a shell script in /tmp, specifying ALL the environment variables with a subsequent BPXBATCH step to run curl.
    Still works for all I know but I've since got a C program using the curl API's to deal with not having so much data in clear text.
    shell.1 = 'export PATH=/bin:/usr/sbin:' || ,                      
              '/apc/portedtools/bash/bin:/apc/portedtools/curl/bin:.' 
    shell.2 = 'export _BPXK_AUTOCVT="ON"'                             
    shell.etc
    
    shell.last = 'bash /somedir/runcurl.sh'   
    shell.0 = number of lines
    x = syscalls('ON')                                           
    fname = '/tmp/'USERID()'.stdin';say 'Writing stdin to 'fname 
    Address syscall "writefile (fname) 600 shell."               
    lrc = rc                                                     
    Say 'writefile finished with rc='lrc                         
    x = syscalls('OFF')                                          ​

    then after running that in  a TSO step

    //UNIX EXEC PGM=BPXBATCH
    //STDIN DD PATH='/tmp/&SYSUID..stdin'

    The runcurl.sh has some bash style setup and then

    curl --cert-type PEM --cacert $CACERT --netrc --silent -O -J -D /tmp/$LOGNAME.head --url $URL > /tmp/$LOGNAME.tmsg

    I got the thing to run well enough without having to worry a lot about what was doing what to the env variables since this approach
    specified everything......and more sophisticated approaches can develop later as time and reading threads like permit.



    ------------------------------
    hank oerlemans
    Senior Technical Specialist
    Self Registered
    North Sydney NSW AU
    ------------------------------