Problems with script running with crontab

Hi,

I'm trying the backup a few information commands of my Check Point FW (it's on a SPLAT linux machine). This is the script I wrote:

#!/bin/bash
 
cd /var/tmp/
 
file1=netstat_`/bin/date +%d%m%y`.txt
file2=ifconfig_`/bin/date +%d%m%y`.txt
file3=cpstatos_`/bin/date +%d%m%y`.txt
file4=cphaprob_`/bin/date +%d%m%y`.txt
filetar=/var/backup_scripts/`hostname`_netstat_`/bin/date +%d%m%y`.tgz


netstat -rn > $file1 
ifconfig -a > $file2 
cpstat os > $file3 
cphaprob -a if > $file4
tar -zcvf $filetar *.txt 
scp $filetar sph1@1.1.1.1:/var/backup/modules/sph1 && rm {*.txt,$filetar} && echo "ok"

If I ran the script Manually it works ok. If I ran it via crontab:

34 6 * * * /var/backup_scripts/backup.sh

three files ($file1 , $file2 and $file3) are generated with no data in them at all (0 bytes). Again , if I manually start the script all the files are created with all the data in them.

Can someone tell me ehat could be wrong with the script ?

10x in advance,

Nirsh

You have to either load your profile in your script or you should use full path for all commands in the script. The cron will give only a minimal default environment for the shell.

--
Anu Bhaskar

I had the same issue some time ago, I had a script named func.sh its path was /usr/local/bin/house_keeping

so my cron entry was something like

05 00 * * * /usr/local/bin/house_keeping/func.sh

it was working fine from command line and no matter what i did i was unable to get it work from cron

Finally I changed the file name for "func.sh" to "func"

and the directory "house_keeping" to "housekeeping" it went through well...:slight_smile:

please refer

Cron, run-parts and script names