11-08-2013 02:23 PM
Hi! Need a little help with an unix x command and its exit code in a macro.
The command is:
x "curl -k &loc. > /var/sas/projects/analyses/data_temp.txt";
Occasionally the web address in &loc. will just 'hang'- nothing happens and the SAS program doesn't continue (I know it's a valid address).
I was thinking something like
x "timeout 2s curl -k &loc. > /var/sas/projects/analyses/data_temp.txt";
might work- if the command times out there is a non-zero exit code so doing something like "retry until exit code = 0" might work (because the macro loops through and populates &loc. with different web addresses I don't want to lose the current value of &loc.; I know the problem is isn't the value of &loc. b/c there is success during subsequent sessions and a different previously successful web address may get stuck...).
How do I get the exit code? Is it sysrc? What would be the best way to keep trying the current &loc. until there is success?
(This macro previously ran with no problems; being able to re-try the current &loc. and see if it gets stuck again will help figure out why a problem has recently arisen).
Thanks for any help!
11-09-2013 04:38 AM
I would look at Piping. SAS(R) 9.4 Companion for UNIX Environments
It eliminates the temp.txt file as possible cause for hang-up. Watch the locking notes.
As curl is a Unix command to transfers docs Why using that when SAS has also those interfaces (FTP SFTP URL)?
SAS(R) 9.4 Statements: Reference (sftp) When this is sufficient it wil give you more control in all options.
Do you want to use curl Unix steps think about running the logical flow system with a professional scheduler like LSF
It will solve timings delay-s hangups etc as monitoring on process-flow proceeding is one of the goals.
11-09-2013 02:15 PM
I find that the SAS log is much clearer if you avoid the X or SYSEXEC command and instead use a PIPE within a DATA _NULL_ so that you can capture any messages that the program you are calling was trying to send to the terminal. You probably also need to watch for special characters in your URL that might confuse SAS or your operating system's shell. The QUOTE() function is useful if the macro variable includes double quote characters.
%let loc=http://mysite.com ;
infile %sysfunc(quote(curl -k &loc. > /var/sas/projects/analyses/data_temp.txt)) pipe ;
11-22-2013 01:24 PM
Thanks! Had to use curl b/c of SSL error (used to use URL but certificates expired). Being able to see the output to terminal in the log helps as well.
I appreciate your time!