?
Solved

Question about gzip in cron job

Posted on 2003-02-19
6
Medium Priority
?
356 Views
Last Modified: 2010-05-18
I created a script at sun env. to back up development files. following is part of the code

cp -p $file_record $file_record.$TIME
chmod 666 $file_record
gzip $file_record.$TIME
mv $file_record.$TIME.gz $file_record.gz
tar rvf $WORKFILE $file_record.gz
/bin/rm  $file_record.gz

TIME is system time (to make sure a uniqure file name).

This script is working fine when typing the command at the prompt. After I set a cron job to run it,"gzip $file_record.$TIME" is failed. Does anyone can explain it?                              
0
Comment
Question by:eric8888
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 7983133
what is $file and $TIME ?

you need to export these variables in the main script.

then cron job will call that main script


other tip of cron,
you need full path for any file you are dealing with.

0
 

Author Comment

by:eric8888
ID: 7989658
That's just a variable in the script. They are used to create unique file name. You can just use any file name to replace $file.$TIME.

Thanks,
0
 

Expert Comment

by:dt64852
ID: 7990377
You don't say what error you got. If you have not already done so, direct your stdout and stderr to a file and rerun.

10 3 * * 0  yourscript > yourlogfile 2>&1

I think you will see either an error message or an unanswered warning in the log.
0
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8000988
ok that is good, now one thing you need to add to your script in order to work from cron job is to define pathname for any command or file


so instead of
cp -p $file_record $file_record.$TIME
chmod 666 $file_record

you should us
MyHome=/home/myname/scripts
cp -p $MyHome/$file_record $MyHome/$file_record.$TIME
chmod 666 $MyHome/$file_record


Try that and let me know

One advice, use "echo" command between actions to debug

MyHome=/home/myname/scripts
echo $MyHome
cp -p $MyHome/$file_record $MyHome/$file_record.$TIME
echo $MyHome/$file_record.$TIME


and for sure at crontab you need to put output messages to output file as dt64852n said

Hamdy





0
 

Author Comment

by:eric8888
ID: 8008755
Finally I figured out the problem.
The path for cron job is /usr/sbin, and gzip is only in /opt/bin (I am shocked that gzip is not in .bin and /usr/bin). Since my PATH does not include /opt/bin/ (but includes /opt/home/peri/bin under which gzip is), the script was working fine from the command mode, but not working in cron job. I changed the script to run gzip as following,
"cp -p $file_record $file_record.$TIME
chmod 666 $file_record
/opt/bin/gzip $file_record.$TIME
mv $file_record.$TIME.gz $file_record.gz
tar rvf $WORKFILE $file_record.gz
/bin/rm  $file_record.gz"
Note that the gzip call is using full path. The script is working fine now.
I have sent a comment to sun to suggest them add gzip in /bin, /usr/sbin and any possible pathes.

Thanks for all your suggestions and advices,
0
 
LVL 9

Accepted Solution

by:
HamdyHassan earned 150 total points
ID: 8010519
Very good.

That is what I was expected and I did mentioned that at my post twice

"other tip of cron,
you need full path for any file you are dealing with."

"in order to work from cron job is to define pathname for any command or file"

because this is the major issue when moving script to run from cron job.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction How to create multiboot configuration with XP\Vista and Windows 7 on it? And most important question - how to do this correctly so not to have any kind of nightmares we get when system gets screwed? First of all one should realize t…
In a recent article here at Experts Exchange (http://www.experts-exchange.com/articles/18880/PaperPort-14-in-Windows-10-A-First-Look.html), I discussed my nine-month sandbox testing of the Windows 10 Technical Preview, specifically with respect to r…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question