Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Why Unix bash shell script does not run my SAS program?

Posted on 2012-03-29
7
Medium Priority
?
839 Views
Last Modified: 2012-03-29
In my Unix bash shell script I am trying to run my SAS program "sasprog1.sas" and then search within the Unix directory for a file "sasprog1.LOG" and then checking for an ERROR within "sasprog1.LOG" file and then open another file ("file1.txt") and then writing some messages to "file1.txt" file?

Please note: "file1.txt" and "sasprog1.LOG" may or may not currently exist in the Unix directory.

Please see why my Unix bash shell script does not run/execute my SAS program. What am I doing wrong here?
Any examples or comments will be very appriciated!


mydir=/start/dir
plog=/start/log
filename=sasprog1.log
search=ERROR
outfile=file1.txt
sas=/products/SAS/SASFoundation/9.2/sas

$sas <$mydir/sasprog1.sas> $plog/$filename     # is this a proper way to run a SAS program and then create SAS log??
find $plog -type f -name $filename |while read file
  do
    RESULT=$(grep $search $file)         # is this correct?      
       if [[ ! -z $RESULT ]]
         then
            echo "Error(s) in $file: $RESULT" >> $outfile
     fi
  done
exit

Open in new window


Curently my script does not even run/execute sasprog1.sas
0
Comment
Question by:labradorchik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 47

Accepted Solution

by:
David earned 2000 total points
ID: 37783347
Assuming you would ordinarily execute:
/products/SAS/SASFoundation/9.2/sas  > /star/log/sasprog1.log

then you would enter:

$sas $mydir$sasprog1.sas > $plog/$filename


Then the RESULT line nedes to be

RESULT=`grep $search $file`
if [ "$RESULT" == "" ] ; then
    echo error ...
fi



You should also add a PATH line at beginning so it can find grep
PATH=/usr/bin:/bin:/sbin    # make sure the path where grep is installed on your host is in the list
0
 
LVL 47

Expert Comment

by:David
ID: 37783362
you can add a "set -x"  at beginning of shell script and it will give a debug dump of exactly what it is doing as it executes.  this will tell you values of all variables as it runs.  Best way to debug a script
0
 

Author Comment

by:labradorchik
ID: 37783430
Thank you very much for your comments, dlethe!!
What do you mean by: "Assuming you would ordinarily execute:
/products/SAS/SASFoundation/9.2/sas  > /star/log/sasprog1.log

Open in new window

"?

I am assignning and openning SAS software with the following line:
 
sas=/products/SAS/SASFoundation/9.2/sas

Open in new window

and then will be running SAS program and creating my sasprog1.log file with the following line:
 
$sas $mydir/sasprog1.sas> $plog/$filename   

Open in new window



So, is this correct?

mydir=/start/dir
plog=/start/log
filename=sasprog1.log
search=ERROR
outfile=file1.txt
sas=/products/SAS/SASFoundation/9.2/sas

$sas $mydir/sasprog1.sas> $plog/$filename    
find $plog -type f -name $filename |while read file
  do
    RESULT= 'grep $search $file'         
       if [["$RESULT" ==""]];
         then
            echo "Error(s) in $file: $RESULT" >> $outfile
     fi
  done
exit

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:labradorchik
ID: 37783886
Anyone else would like to comment on the obove Unix script?
0
 
LVL 47

Expert Comment

by:David
ID: 37784110
no,  you need `   not  the single quote.

many ways to do the if, depending on exact version of shell, but most portable would be

if [ "$RESULT" == "" ]
then

fi
Note the whitespace

I  have no idea if the find $plog ... line will do what you want, that is a function of the output syntax of the sas command.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 37784327
There's no need for the find, assuming you don't have multiple sasprog1.log in sub-directories.

That being the case, you can simply make the script

#!/bin/bash
mydir=/start/dir
plog=/start/log
filename=sasprog1.log
search=ERROR
outfile=file1.txt
sas=/products/SAS/SASFoundation/9.2/sas

$sas $mydir/sasprog1.sas >$plog/$filename

result=$(grep $search $plog/$filename) && echo "Error(s) in $plog/$filename: $result" >>$outfile

Open in new window

0
 

Author Comment

by:labradorchik
ID: 37784353
Great!! Thank you very much for your comments, dlethe!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this article, we’ll look at how to deploy ProxySQL.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question