1834391 Members
1742 Online
110066 Solutions
New Discussion

crontab and gzip

 
SOLVED
Go to solution
Ahmed_58
Regular Advisor

crontab and gzip

Hi,
I have a script where scp file and then gzip the file which is working OK, but when run it via root crontab the gzip step not work!? any idea way?
-----------my script ---------------
cd /usr3/live/BATELCO/NRT/NRT_src
ls *NR_BHRBT_* | read LINE
if [ $? = 0 ]
[ -f "$LINE" -a -z "$(fuser $LINE 2> /dev/null)" ]
then
mv $LINE /usr3/live/BATELCO/NRT/NRT_backup
date | read sdate
echo Start copy $LINE $sdate... >>/usr3/live/BATELCO/NRT/NRT_daily_out.log
cd /usr3/live/BATELCO/NRT/NRT_backup
scp $LINE BHRBTF@bat-abc:/
if [ $? -eq 0 ];then
gzip $LINE
date | read edate
echo Finish copy $LINE $sdate >>/usr3/live/BATELCO/NRT/NRT_daily_out.log
else
cd /usr3/live/BATELCO/NRT/NRT_backup
mv $LINE /usr3/live/BATELCO/NRT/NRT_src
cd /usr3/live/BATELCO/NRT
date | read edate
echo Failed copy of $LINE "$edate" connection problem >/usr3/live/BATELCO/NRT/NRT_faild.log
cat NRT_faild.log >> NRT_daily_out.log
NRT_faild.log
fi
else
cd /usr3/live/BATELCO/NRT
date | read edate
echo Failed $LINE "$edate"... BUSY or NO file >/usr3/live/BATELCO/NRT/NRT_faild.log
fi
8 REPLIES 8
mobidyc
Trusted Contributor
Solution

Re: crontab and gzip

Hi,

the first thought in my mind is to give the full path to gzip.
or add a PATH var in front of you script.
eg.
PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin

could you send us any error log ?

Cheers,
Cedrick Gaillard
Best regards, Cedrick Gaillard
Ganesan R
Honored Contributor

Re: crontab and gzip

Hi Ahmed,

Specify the full path of gzip executable instead of just specifying "gzip $LINE" when you schedule in crontab.

Cron will not inherit any environment varialbles including $PATH
Best wishes,

Ganesh.
Torsten.
Acclaimed Contributor

Re: crontab and gzip

It's always the same reason, because cron has a very "poor" environment, you either need to set the PATH variable or use full pathes to each command.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Suraj K Sankari
Honored Contributor

Re: crontab and gzip

Hi,

Each of your command which you are using into this script needs full path then only cron can successfully executed.

Suraj
Ahmed_58
Regular Advisor

Re: crontab and gzip

Hi,
Thanks for replay....
I add full patch, but still not worked....

gzip /usr3/live/BATELCO/NRT/NRT_backup/$LINE

Rgds,
Ahmed
Torsten.
Acclaimed Contributor

Re: crontab and gzip

the full path to **gzip** and all other application, e.g.

/usr/contrib/bin/gzip

instead of just

gzip

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Ahmed_58
Regular Advisor

Re: crontab and gzip

thanks it is woking now,... all rewarded with 10 points.
Torsten.
Acclaimed Contributor

Re: crontab and gzip

"...all rewarded with 10 points..."

You need to click "submit points".

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!