/usr/bin/bkp.sh line 22: p4: command not found
In this blog I trying to [solved] /usr/bin/bkp.sh line 22: p4: command not found: The person ask the question and I hope I find the answer according to the given situation. I hope this will work.
There are 2 set of scripts which are running right now on the server as both are mention below:
$ 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
Problem is 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
:
Output:
====================================================================================
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)
Bash Script I write is as under:
#!/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!"
The error showing is as under:
/usr/bin/bkp.sh: line 22: p4: command not found
This can mean just that $PATH
does not include /usr/local/bin
, that’s all. So modify your cron script and add this after your shebang:
#!/bin/bash
set -e
PATH="/usr/local/bin:$PATH"
- I think your script will work if you don’t use the ‘echo’ statements. In the past I came across a similar issue when running a couple of python scripts in crontab. I believe cron runs an instance of the terminal without support for IO to the screen. If you need to store any information which was being printed to the screen you should append it to a log file.
Below is option to install the cron as additional pakage:
How to install the cron:
Before installing cron on an Ubuntu machine, update the computer’s local package index:
sudo apt update
Then install cron with the following command:
sudo apt install cron
You’ll need to make sure it’s set to run in the background too:
sudo systemctl enable cron
or
sudo /etc/init.d/cron start
Following that, cron will be installed on your system and ready for you to start scheduling jobs.
I hope this will solve the error you guys facing. If you have better solution or any thing to ask feel free to comment in comment section.