labradorchik
asked on
How to check in Unix bash script if SAS log has any errors?
Hi everyone!
I am trying to do a few things in my bash script (script1.sh): pass logicals/variables to my SAS program (program1.sas), execute SAS code (program1.sas), check with "errstat" for specific errors related to SAS code conditions that I set up in my SAS code, and also check with "logerrchk" SAS log file for any errors in the SAS log.
I think most of the script is correct but I am not sure about both checking errors (errstat" and "logerrchk").
Please note: variable/logicals (file1, file2, plog, and errstat) are also defined in the SAS program.
Please provide any suggestions or examples if you can.
Here is what I have so far:
Please let me know if anything in this script can be done differently or in a more efficient way.
Any suggestions would be appreciated!
Thank you!
I am trying to do a few things in my bash script (script1.sh): pass logicals/variables to my SAS program (program1.sas), execute SAS code (program1.sas), check with "errstat" for specific errors related to SAS code conditions that I set up in my SAS code, and also check with "logerrchk" SAS log file for any errors in the SAS log.
I think most of the script is correct but I am not sure about both checking errors (errstat" and "logerrchk").
Please note: variable/logicals (file1, file2, plog, and errstat) are also defined in the SAS program.
Please provide any suggestions or examples if you can.
Here is what I have so far:
#!/bin/bash
#script1.sh
# Creating variables for directories
export DATADIR1=/root/alldirs/2018/data1
export DATADIR2=/root/alldirs/2018/data2
export DATADIR3=/root/alldirs/2018/data3
export PROGDIR1=/root/alldirs/2018/prog1
#Creating variables for data files that are used in program1.sas and final log file
export file1=${DATADIR1}/sasdata1.sas7bdat
export file2=${DATADIR2}/sasdata2.sas7bdat
export plog=${DATADIR3}/sas_program.log
#executing SAS program
sas ${PROGDIR1}/program1.sas -log ${DATADIR3}/program1.log
#checking for errors in SAS log file
logerrchk=$?
if [[ "$logerrchk" !=0 ]];
then
echo "--- Error: Abnormal end in program program1.sas. Check log file! ---" >> $plog
exit 2
else
echo "--- Program1.sas run successfully! ---" >> $plog
fi
#checking for specific errors that are related to SAS code conditions
while IFS=read -r rec; do
errstat=${rec:0:1}
done < $errstat
if [[ "$errstat" ==0 ]];
then
echo "--- All calculations in Program1.sas are successful! ---" >> $plog
exit 2
else
echo "--- Program1.sas has a problem with some calculations. Check log file! ---" >> $plog
fi
exit 0
Please let me know if anything in this script can be done differently or in a more efficient way.
Any suggestions would be appreciated!
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
NP. A mail might easily get lost. (and staying logged on might help as well).
I hope all is working.
I hope all is working.
ASKER