We help IT Professionals succeed at work.
Get Started

script won't run in cron but runs on the command line

274 Views
Last Modified: 2014-12-12
This script runs just fine when I run it from the command line, but it bombs on the mailx piece when I try to run it from a cron job.  Any ideas?

Thanks in advance,
David


#!/bin/ksh

now=current
set -x
LOGDIR=/opt/VRTSsfmcs/Backup
THIS_SCRIPT=`basename $0`
LOGFILE=$THIS_SCRIPT_$now.log
MAILLIST="david@itmemphis.com"
MAILSTRING="lnxutil VOM Backup Result $now"

function logger {

        mkdir /opt/VRTSsfmcs/Backup/VOM_Backup_$now
        echo "Creating Logs"

                echo "Creating Logfile"
                mkdir -p $LOGDIR
                exec 1> $LOGDIR/$LOGFILE 2>&1
                mv $LOGDIR/$LOGFILE /opt/VRTSsfmcs/Backup/VOM_Backup_$now
}

function clean {
        echo "Removing old file"
        rm -r  /opt/VRTSsfmcs/Backup/VOM_Backup_last
        echo "Changing file name"
        mv  /opt/VRTSsfmcs/Backup/VOM_Backup_$now  /opt/VRTSsfmcs/Backup/VOM_Backup_last

        echo "Clean Complete"
}

function Do_Backup {
        echo "Running the backup process...."

        /opt/VRTSsfmcs/config/adm/vom_bkup.pl --backup /opt/VRTSsfmcs/Backup/VOM_Backup_$now

        echo "Backup Complete"
}

function mailer {
        echo "Sending Email to david@itmemphis.com"
        cat /opt/VRTSsfmcs/Backup/VOM_Backup_$now/$now.log | mailx -s "$MAILSTRING" $MAILLIST
}

clean
logger
Do_Backup
mailer

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2007
Commented:
This problem has been solved!
Unlock 3 Answers and 34 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE