Tag Archives: HRINST

Test exit status of last cmd via ssh

By jack.bauer

see below for a housekeeping script which constructs an ssh cmd using some server/path/sudo info found in $HRINST.
the script should hop to each server and if it finds a file to cleanup, moves it to the archive dir
if there is nothing to move, it should report so and email the output
currently i have got it working to perform the cleanup but struggling at the stage where it should report the error if nothing found.

was trying to perform a test on the exit status of the mv comd and if !=0 then report the error? not quite working as the cmd is issued via ssh. pls help

Code:


cat $HRINST | while read configline

do
myhost=`echo $configline | awk -F":" '{print $1}'`
mypath=`echo $configline | awk -F":" '{print $2}'`
myuserid=`echo $configline | awk -F":" '{print $3}'`
myinstance=`echo $mypath | awk -F"/" '{print $5}'`
myyesterdaylog=`echo $myinstance| sed -e 's/_/./g'`

echo "Files cleaned up on $myinstance"
echo " "
ssh -n $myuserid@$myhost "ls $mypath/OrderDump*"
ssh -n $myuserid@$myhost "mv $mypath/OrderDump* $mypath/archive/"
echo " "
echo " "

done >> $LOG 2>&1

echo "Executed housekeeping script cleanup.sh" >> $LOG 2>&1


Code:


function TestCleanup {

if [ $? != 0 ]; then
printf "nothing to remove in $myinstance"
fi;
}


Source: FULL ARTICLE at The UNIX and Linux Forums