Solved

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

Posted on 2012-03-29
7
833 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
  • 3
  • 3
7 Comments
 
LVL 47

Accepted Solution

by:
dlethe earned 500 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:dlethe
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

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

Expert Comment

by:dlethe
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MacOS and programming in React 7 28
TypeError: Users.save is not a function 3 41
Sql Join Problem 2 33
constraint check 2 17
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now