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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.