http://www.perlmonks.org?node_id=969258

stahl has asked for the wisdom of the Perl Monks concerning the following question:

Oh Great Perl Monks, I come to you in the most dire of circumstances. I am but a lowely per lnewbie, and google has been a great friend to me. However, it has not been able to answer my greatest question. I created a 3 line perl script to call a shell script(I will list both Below) The current script is using system(), i have however tried both backticks and exec to accomplish my endgoal. None of these have worked. Also i have tried getting the stdout and in statements to work unsuccessfully. Im sure it is something to do with the otuput getting lost and not knowing where to go, but i wont know The real goal of this script is to automate the sophos updating process threw out my unix enviroment, by using this script to output to a file then i will make a nagios script to read the file and check for failed/successful updates. KSH/SH from what i have read and been told will not do inherently what i want it to do, which is why i come to you oh wise an great monks of perl. The OS running this is : AIX 5.3 Tech level 10

Below i shall insert very small code examples: The first script is call savupdate.sh it is apart of the sophos for unix Antivirus client.

#! /bin/sh # # Copyright (c) 1989-2009 Sophos Plc. All rights reserved. # All rights reserved. # CIDREPDIR=`dirname $0` INSTALLORCOMMONDIR=$CIDREPDIR/.. PythonInterpreter=$INSTALLORCOMMONDIR/engine/python [ -f $PythonInterpreter ] || PythonInterpreter=$INSTALLORCOMMONDIR/eng +ine/_/python ORIGINAL_PYTHONPATH="${ORIGINAL_PYTHONPATH-${PYTHONPATH}}" ORIGINAL_LD_LIBRARY_PATH="${ORIGINAL_LD_LIBRARY_PATH-${LD_LIBRARY_PATH +}}" ORIGINAL_PYTHONHOME="${ORIGINAL_PYTHONHOME-${PYTHONHOME}}" export ORIGINAL_PYTHONPATH export ORIGINAL_LD_LIBRARY_PATH export ORIGINAL_PYTHONHOME if [ -f $PythonInterpreter ] then #Settings for when SAV is installed INSTDIR=$INSTALLORCOMMONDIR PYTHONHOME=$INSTDIR PythonStdModules=$INSTDIR/engine/python25.zip PythonLibsDir=$INSTDIR/lib/python2.5/lib-dynload PythonModsDir=$INSTDIR/engine/_ LD_LIBRARY_PATH=$INSTDIR/lib PYTHONHOME=$INSTDIR MINIPKG= else PLATFORM=`uname -s | LC_ALL=C tr '[:upper:]' '[:lower:]' | LC_ALL= +C tr -d '-'` export PLATFORM if [ $PLATFORM = "linux" ] ; then PROCESSOR=`uname -m` else PROCESSOR=`uname -p 2>/dev/null` if [ $? -ne 0 ] || [ $PROCESSOR = "unknown" ] ; then PROCESSOR=`uname -m` else PROCESSOR=`uname -p` fi fi #Settings for when SAV is not installed COMMONDIR=$INSTALLORCOMMONDIR if [ -f /etc/redhat-release ] && grep -q "Red Hat Linux release 9 +(Shrike)" /etc/redhat-release ; then ARCHITECTURE=rh90 elif echo $PROCESSOR | grep "[ix].*86" > /dev/null 2>&1 ; then ARCHITECTURE=x86 else ARCHITECTURE=$PROCESSOR fi CoreDir=sav-${PLATFORM}/$ARCHITECTURE DISTDIR=$COMMONDIR/../.. PythonInterpreter=$DISTDIR/$CoreDir/engine/_/python PythonStdModules=$COMMONDIR/engine/python25.zip PythonLibsDir=$DISTDIR/$CoreDir/lib/python2.5/lib-dynload PythonModsDir=$COMMONDIR/engine/_:$DISTDIR/$CoreDir/engine/_ LD_LIBRARY_PATH=$DISTDIR/$CoreDir/lib PYTHONHOME=$DISTDIR MINIPKG=--minipkg fi APPPATH=$CIDREPDIR:$CIDREPDIR/cidrep.zip:$CIDREPDIR/installer.zip:$INS +TALLORCOMMONDIR/engine/util.zip PYTHONPATH=$PythonLibsDir:$PythonModsDir:$PythonStdModules:$APPPATH export PYTHONPATH export PYTHONHOME export LD_LIBRARY_PATH chmod 0755 $PythonInterpreter 2>/dev/null unset LIBPATH exec $PythonInterpreter -c "import savupdate.Updater,sys; sys.exit(sav +update.Updater.main(sys.argv))" "$CIDREPDIR" $MINIPKG "$@"

This is the scripts output:

root# ./savupdate.sh Downloading http://xxx.xxx.xxx.xxx:8000/CIDs/S000/EESAVUNIX/AIX_PPC/server.inf Downloading http://xxx.xxx.xxx.xxx:8000/CIDs/S000/EESAVUNIX/AIX_PPC/cidsync.upd 16763 bytes downloaded in 0.028047 secs (583.670512 KiB/s) Downloading http://xxx.xxx.xxx.xxx:8000/CIDs/S000/EESAVUNIX/AIX_PPC/config/index.spec Downloading http://xxx.xxx.xxx.xxx:8000/CIDs/S000/EESAVUNIX/AIX_PPC/talpa-custom/index.spec Downloading http://xxx.xxx.xxx.xxx:8000/CIDs/S000/EESAVUNIX/AIX_PPC/cac.pem 1131 bytes downloaded in 0.020245 secs (54.556092 KiB/s) Downloading http://xxx.xxx.xxx.xxx:8000/CIDs/S000/EESAVUNIX/AIX_PPC/mrinit.custom Downloading http://xxx.xxx.xxx.xxx:8000/CIDs/S000/EESAVUNIX/AIX_PPC/MRInit.custom Downloading http://xxx.xxx.xxx.xxx:8000/CIDs/S000/EESAVUNIX/AIX_PPC/mrinit.conf 461 bytes downloaded in 0.014299 secs (31.484052 KiB/s) Successfully updated Sophos Anti-Virus from http://xxx.xxx.xxx.xxx:8000/CIDs/S000/EESAVUNIX

The Next script is the smiple 1 lines i wrote, please dont laugh oh great monks for i am in training.

#!/usr/bin/perl ###################################### # #Sophos Update Script # # ###################################### system("/Antivirus/sophos-av/update/savupdate.sh 1>/tmp/updater 2>&1") +;

After running this script from command line it works every time. However when trying to run it from crontab it fails everytime..it has also been the case with every other KSH/SH/Perl script i have tried to write...they all work great from command line no problems, however when used with crontab they all fail. I have check to make sure the scripts themself are running by having an active ps -ef going just to make sure they are being executed. It seems that the output and how it is directed is what is illuding me.

Monks, if you could help solve this issue for me i would be eternally grateful! Thank you, your monk in training, Stahl

~