Hi,
I'm trying to create a shell script to execute SAS in command line. The objetive is use it to run SAS programns in crontab. The shell script created use two parameters, $1 and $2. The first parameter ($1) is the complete path of SAS program to execute and the second one ($2) is the user's name of the responsible.
Shell
--------
##
$ which sasprogram
/usr/bin/sasprogram
$ more /usr/bin/sasprogram
#!/bin/sh
umask 007
PATH=.:opt/bin:/bin:/usr/sbin:/usr/bin:/usr/ccs/bin:/GNU/bin/make:/usr/ucb:/sas/software/SASFoundation/9.2/bin
export PATH
progpath=`dirname "$1"`
prog=`basename "$1"`
cd $progpath
nohup /<path>/BatchServer/sasbatch.sh -log /<path>/logs/$prog.#Y_#m_#d.log -batch -noterminal -logparm "rollover=session" -xcmd -autoexec /<path>/autoexec.sas -sysparm "$1|$2" &
$
##
----
I'm using the following command line to execute:
sasprogram /<path>/SAScode.sas UserName
After run, log file is empty as shown below:
$ cat /<path>/logs/SAScode.sas.2017_06_26.log
NOTE: Log file opened at Mon, 26 Jun 2017 16:11:58.754
And in nohup.out log the following message appears:
$ cat nohup.out
/<path>/sasbatch.sh[46]: UserName: not found
Any ideia what is going on?
Regards,
Inspect line 46 of sasbatch.sh to see why Username ends up being taken for a UNIX command.
What I see is that in your call to sasbatch.sh you do not supply the program path and name. You set the log and the autoexec, but there's no -sysin or equivalent. That is the reason for the empty log.
Looks like you have bug in the sasbatch.sh program that your program is calling. Most likely it is not properly transfering its input parameters onto the SAS executable. In particular it looks like quotes around the pipe character in the value of -sysparm option are not being honored and so UserName is being interpretted by the shell as the name of the program to pipe the output of the SAS job into. Is it passing the parameters using "$@" ?
You could try calling it with \| instead of | to protect the pipe character, but I think you probably need to fix that other script.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.