Good day Guys!!!
I am currently making a script in AIX, the script runs a SAS job, the owner of the script is the root, but the SAS jobs cannot be run by the root, as it should be run by a user 'sasia'. But inside the script, root creates a logfile, so what I need is just to su to sasia for the certain job and then go back to the original user. the script is written below. Pls. help
#!/bin/sh
function logrc
{
if [ -f $drv/$batchname".err" ]
then
cat $drv/$batchname".err"|grep 0
rcode=$?
fi
echo $step $rcode $dtx $bpsw $desc >> $drv/$batchname".log"
if [ $bpsw != 1 ]
then
if [ $rcode != 0 ]
then
echo >> $drv/$batchname".log"
echo "Job Failed at "$step"." >> $drv/$batchname".log"
echo "Recovery Procedure:" >> $drv/$batchname".log"
if [ -f $rdrv/$batchname".rpm" ]
then
cat $rdrv/$batchname".rpm" >> $drv/$batchname".log"
else
echo "No Recovery Procedure." >> $drv/$batchname".log"
fi
exit $rcode
fi
fi
return $rcode
}
function step00
{
step=step00
desc="Delete exisitng trigger files"
cd /sasprog/triggers
if [ -f $st ]
then
rm $st
echo $st " deleted "
else
echo $st" does not exist"
fi
if [ -f $ut ]
then
rm $ut
echo $ut " deleted"
else
echo $ut " does not exist"
fi
echo date
rcode=$?
logrc
}
function step01
{
step=step01
if [ "$rrstep" != "" ] && [ "$rrstep" != "$step" ]
then
echo $step skipped
return 0
fi
desc="Call SAS job"
Quoteme() {
if [ $# -gt 1 ]; then
quoteme="\"$*\""
else
quoteme=$1
fi
}
cd `cat /sasconfig/BPICRMS/jobpath/prereq`
cmd="/sas9/SAS913/sas"
for arg in "SET_RUN_CONTROL_TABLE_FOR_ALAS.sas"
do
Quoteme $arg
tmp="$quoteme"
cmd="$cmd $tmp"
done
$cmd
rcode=$?
logrc
}
#main script
drv=/sasprog/joblog
rdrv=/sasprog/Lev1/rdrv
batchname=SET_RUN_CONTROL_TABLE_FOR_ALAS
dtx=`date +'%y%m%d'`" "`date +'%H%M%S'`
rrstep=""
bpsw=0
ut=U_SET_RUN_CONTROL_TABLE_FOR_ALAS.txt
st=S_SET_RUN_CONTROL_TABLE_FOR_ALAS.txt
if [ "$1" != "" ] && [ "$1" != "step00" ]
then
echo Job Restarted at $1 $dtx >> $drv/$batchname".log"
rrstep=$1
else
echo Job Started $dtx > $drv/$batchname".log"
rrstep=""
fi
step00
step01
exit $rcode
what I need is to revise the functyion 01 so that it will switch user to sasia, run the sasjob and then go back as root. Thanks in advanced for the help. Thanks
#end of script