Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing a cron job - how do I.....?

Status
Not open for further replies.

pixelwarrior

Technical User
May 7, 2002
4
CA
*newbie alert!*

OK, I've got the basic idea. I have managed to write a simple cron job and implement it....every day @ 2:00 my error_log is copied to a new file, and then it and my access_log are truncated back to 0. I'm happy with that.

Now, here's where I need some help. I also need to automate a perl script to run daily, let's call it blah.pl. It is a command-line script (i.e. it must be run thru a terminal session to my host rather than thru a browser). That would be easy enough using the 'perl' command and the full path to the script. However, the script requires a cfg file, let's call that blah.cfg. When I run the blah.pl manually, it then prompts me for the location of blah.cfg, which is actually in the same directory as blah.pl.

My question is, how do I accomplish that in the textfile I create for my cronjob? I tried this:

0 1 * * * /user/ blah.cfg

but it did nothing. Do I need to give the full path to blah.cfg? Or should I add a % character in front of blah.cfg? Or maybe I can't do this at all and I'm just retarded?

Any help you can provide would be greatly appreciated.

pixel_warrior@hotmail.com
 
crontab -l > textfile
edit textfile so it has complete paths to everything

1 1 * * * /usr/bin/perl /user/ \ /home/blah.cfg </dev/null 2>&1 >/dev/null

crontab textfile
 
Warrior:

You can use the first suggestion, but there's always another way of doing something: change directory to /usr/ and then run your program:

0 1 * * * cd /user/ /usr/bin/perl blah.pl ./blah.cfg

1) The semi-colon strings two unix commands together.

2) The ./blah.cfg makes sure you only use the blah.cfg file in the current directory.

Since I'm a total Perl newbie, I have a question for you: If the Perl invocation is in blah.pl, #!/usr/bin/perl, can't you:

0 1 * * * cd /user/ ./blah.pl ./blah.cfg

Regards,


Ed
 
Thanks!! I will try these suggestions.

Gheist, I'm not sure I understand the /dev/null references. Are they necessary to end the process?

Olded, I didn't write the script. Believe me, I'm a newbie too. I would tend to think there could be/should be/would be some way to include the required cfg file in the script itself, but hey...that's a topic for a different forum. :)

Thanks again.
 
</dev/null simulates an input (as you said .pl ran from your terminal)

2>&1 was meant to direst stderr to stdin

>/dev/null stdin to backup device (not /dev/null on first attempts)
 
gheist -- Not sure what you mean by backup device? Mike
______________________________________________________________________
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
In case anyone is interested, I managed to solve this dilemma, with thanks to GHeist. Yes, it was FULL paths that were necessary, including the backslash escape.

1 1 * * * /usr/bin/perl /user/ \ /usr/
Didn't need the /dev/null, as I was not expecting output from the script, it exists solely to truncate a textfile based on expiration dates listed therein.

Thanks all !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top