Link to home
Start Free TrialLog in
Avatar of Christian Palacios
Christian PalaciosFlag for Canada

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/$LATESTFILE".  It just shows me /data99/backup/ with nothing else.

Thank you in advance,
- Christian
Avatar of James Bilous
James Bilous
Flag of United States of America image

Are you looking in the correct folder? Maybe try providing an absolute path to the folder that should contain the zip files.
Avatar of Christian Palacios

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/
SOLUTION
Avatar of James Bilous
James Bilous
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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/$LATESTFILE oracle@10.44.28.16:/dbdump/diskos_prod.zip
echo "/data99/dbdump/backup/$LATESTFILE"

Thanks!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ah, that was it!!  Thanks very much James.  I'll close this question.

- Christian
Perfect solution!