I have set my crontab to run 2 script:
$ crontab -l
0 20 * * * /usr/bin/bkp.sh --silent > /home/perforce/logs/bkp.log 2>&1
0 21 * * * /usr/bin/flsbk.sh --silent > /home/perforce/logs/flsbk.log 2>&1
The first script is not running.
I set up on crontab -e
not sudo crontab -e
The error I have is this. From /home/perforce/output.log
:
====================================================================================
Starting Backup
====================================================================================
Output location: /home/perforce/output.log
Running p4 verify...
/usr/bin/bkp.sh: line 22: p4: command not found
Done! (No error)
Running p4 admin checkpoint...
/usr/bin/bkp.sh: line 46: p4: command not found
Done!
/usr/bin/bkp.sh: line 51: p4: command not found
(Error)
And my script is this:
#!/bin/bash
echo
echo "===================================================================================="
echo "Starting Backup"
echo "===================================================================================="
# Defines output folder and log name
OUTPUT_FOLDER='/home/perforce/'
OUTPUT_FILE='output.log'
OUTPUT=$OUTPUT_FOLDER$OUTPUT_FILE
echo "Output location: " $OUTPUT
# Creates a temp file
TMPFILE=`mktemp`
echo -n "Running p4 verify..."
# Run the p4 and send the output to the temp file
p4 verify -q //... > $TMPFILE
echo -n " Done!"
# Check if it's empty (no error)
# Copy the content to another variable, so we don't mess up with the original output
RESULT=`cat $TMPFILE`
if [ "$RESULT" != "" ];
then
echo " (Error, saving to log)"
# Save error on output file
`echo $RESULT > $OUTPUT`
exit
fi
echo " (No error)"
echo -n "Running p4 admin checkpoint..."
# Run the p4 and send the output to the temp file
p4 admin checkpoint > $TMPFILE
echo -n "Done!"
# The file created by the last command
COUNTER=`p4 counter journal`
FILE=/perforce_depot/checkpoint.$COUNTER
# Check if the file was created
if [ -f "$FILE" ]
then
echo " (No error)"
else
echo " (Error)"
exit
fi
echo -n "Backing up ..."
# Finaly, let's create the backup
#`cp -r /perforce_depot '/media/perforce/Seagate Backup Plus Drive/perforcebk'`
START=$(date +%D)
FOLDER_NAME=`echo $START | tr -s '/' | tr '/' '_'`
FOLDER_PATH='/media/perforce/BackupDrive/perforcebk'
BACKUP_PATH=$FOLDER_PATH/bkp_$FOLDER_NAME
mkdir -p $BACKUP_PATH
cp -r /perforce_depot $BACKUP_PATH
echo " Done!"
p4
is located into /usr/local/bin
Any one have any idea why i am getting that error? If I ssh to the machine and run manually sh bhp.sh
it runs without a problem and any errors.
p4
to/usr/local/bin/p4
? – Vladimir May 17 '13 at 13:11Cron runs from crontab based on the owner of that crontab.
– Argusvision May 17 '13 at 14:110 20 * * * /usr/bin/bkp.sh --silent > /home/perforce/logs/bkp.log 2>&1 0 21 * * * /usr/bin/flsbk.sh --silent > /home/perforce/logs/flsbk.log 2>&1 the second job runs fine but the first job i got these errors please note that the 2nd job consist only of a cp command – Savio Da Silva May 17 '13 at 14:16
crontab -l
? – Argusvision May 17 '13 at 14:310 20 * * * /usr/bin/bkp.sh --silent > /home/perforce/logs/bkp.log 2>&1 0 21 * * * /usr/bin/flsbk.sh --silent > /home/perforce/logs/flsbk.log 2>&1
– Savio Da Silva May 17 '13 at 14:35/usr/local/bin/p4
as suggested by Vladimir? – Argusvision May 17 '13 at 14:51/usr/local/bin/p4
or add p4 to/usr/bin
– Dan May 17 '13 at 13:15