Christian Palacios
asked on
Command not running in Linux script under a cron job
Hi there,
I created a script (oracle-copy.sh) that retrieves the most recent ZIP file and then stores the name of it in a variable. After it does that, it runs a "scp" command to copy that ZIP file to a remote server. When I run the script manually, it does the copy just fine, but when I set this script to run under a cron job every day, it seems to fail at the command that retrieves the latest ZIP file name.
This commands retrieves the name: LATESTFILE=$(ls *.zip -t1 | head -n1)
I can tell that it doesn't get the file name because I then run this command and the name is not attached: echo "/data99/backup/$LATESTFIL E". It just shows me /data99/backup/ with nothing else.
Thank you in advance,
- Christian
I created a script (oracle-copy.sh) that retrieves the most recent ZIP file and then stores the name of it in a variable. After it does that, it runs a "scp" command to copy that ZIP file to a remote server. When I run the script manually, it does the copy just fine, but when I set this script to run under a cron job every day, it seems to fail at the command that retrieves the latest ZIP file name.
This commands retrieves the name: LATESTFILE=$(ls *.zip -t1 | head -n1)
I can tell that it doesn't get the file name because I then run this command and the name is not attached: echo "/data99/backup/$LATESTFIL
Thank you in advance,
- Christian
Are you looking in the correct folder? Maybe try providing an absolute path to the folder that should contain the zip files.
ASKER
Here is the entry in the crontab file:
45 22 * * * /data99/backup/oracle-copy .sh >> /var/log/cyphertite.log
The script is in the same location as the ZIP files.
When I view cyphertite.log, all I get is this:
Starting backup of file to file /dbdump/diskos_prod.zip
/data99/backup/
45 22 * * * /data99/backup/oracle-copy
The script is in the same location as the ZIP files.
When I view cyphertite.log, all I get is this:
Starting backup of file to file /dbdump/diskos_prod.zip
/data99/backup/
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you. Here is the content of the .sh file. I am putting the full path so maybe just a CD first as you suggested?
#!/bin/sh
#
LATESTFILE=$(ls *.zip -t1 | head -n1)
#Display message about starting the backup
echo "Starting backup of file $LATESTFILE"
scp /data99/dbdump/backup/$LAT ESTFILE oracle@10.44.28.16:/dbdump /diskos_pr od.zip
echo "/data99/dbdump/backup/$LA TESTFILE"
Thanks!
#!/bin/sh
#
LATESTFILE=$(ls *.zip -t1 | head -n1)
#Display message about starting the backup
echo "Starting backup of file $LATESTFILE"
scp /data99/dbdump/backup/$LAT
echo "/data99/dbdump/backup/$LA
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ah, that was it!! Thanks very much James. I'll close this question.
- Christian
- Christian
ASKER
Perfect solution!