We help IT Professionals succeed at work.

How to send a SAS log file to a different directory in the Unix bash shell script?

labradorchik
labradorchik used Ask the Experts™
on
How can I send SAS log file "saslog.log" to an another directory in the Unix bash shell?
When I run my script with SAS program "mysasprogram.sas" I am getting my SAS log file in my current directory "/user/name", but I want it to go to the "/user/name/log" directory.  In the below script I can send "saslog.log" to the "/user/name/log" directory, but it always appears to be empty. Is there any other way to send a SAS log to an another directory?

mydir=/user/name              # my current directory
proglog=/user/name/log     # directory for SAS logs

sas=/products/SAS/SASFoundation/9.2/sas
$sas $mydir/mysasprogram >$proglog/saslog.log

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2013
Top Expert 2013

Commented:
Hi,

with your method you will redirect to $proglog/saslog.log what would otherwise appear on the screen.

Do you get any output on the screen with just "$sas $mydir/mysasprogram" without the "> ..." part?

I don't assume so, because I rather believe that "mysasprogram" implements its own way of writing a logfile
which cannot be changed by a simple shell redirection.

Please examine "mysasprogram". Do you see any logging method therein?

wmp

Author

Commented:
Thank you, woolmilkporc!

nothing appears about the SAS log on the screen when I run my script with
"bash -xv <script>"

I get two log outputs:
1.  saslog.log file in the $mydir, which is automatically created and has all logs for my SAS program.
2.  saslog.log file in the $proglog, which I directed, but its totally empty file.

Do  you know if there is a specific command in the Unix bash shell script to redirect SAS log to an another directory?
Most Valuable Expert 2013
Top Expert 2013

Commented:
Seems you didn't fully read my previous comment.

With bash commands you can only redirect what would otherwise appear on the screen.

The shell opens and later closes the target of the redirection, but when the application does not write anything to the screen the target file will remain empty, and that's what you're observing.

The only way to modify the target of the internal SAS logfile is changing the SAS program itself (or its configuration, if there's any).

Author

Commented:
Hmm... OK, question:
In this case, may I redirect the automatic SAS log file, which is correct, to an another directory right after my script runs the SAS program?
Most Valuable Expert 2013
Top Expert 2013
Commented:
Well,

not "redirect", but "move":

mydir=/user/name              # my current directory
proglog=/user/name/log     # directory for SAS logs

sas=/products/SAS/SASFoundation/9.2/sas
$sas $mydir/mysasprogram

mv $mydir/saslog.log $proglog/

Author

Commented:
Thank you!
Do you think -log or -altlog might be a good option instead of mv for redirection?
http://support.sas.com/onlinedoc/913/getDoc/en/hostunx.hlp/a000309127.htm
Topic Advisor
Most Valuable Expert 2016
Commented:
Yes this is a good option, when -log or -altlog are command line switches that are supported by sas.exe or your .sas program then this will be easier. That way you create your logfiles at the 'correct' location and no move afterwards is necessary.

Author

Commented:
-log works! Thank you!!