Link to home
Start Free TrialLog in
Avatar of Dartagnan324
Dartagnan324

asked on

Perl cron jobs

Hi

Everyday, I run ./apple which outputs some data on the screen.

I need to create a cron job to run this command on weekends and print the data into a file I can get later on monday.

From what I gathered so far, you just do:

20 9 * * 6 /usr/local/program.pl

will run program.pl at 9:20 on Saturday.  However, what do I do if apple requires "./apple" to run and what is some sample code to output the data to a file?

Dartagnan
ASKER CERTIFIED SOLUTION
Avatar of owensleftfoot
owensleftfoot

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
Avatar of jlevie
jlevie

If your Linux username were to be dartagnan and you were in your home directory when you executed ./apple, the cron job for that might look like:

20 9 * * 6 /home/dartagnan/apple
-- or--
20 9 * * 6 /home/dartagnan/apple >/home/dartagnan/apple.results
-- or --
20 9 * * 6 /home/dartagnan/apple >/home/dartagnan/apple.results 2>&1

Since cron will mail to the user owning the crontab any output generated from a cron job the first example will send the output from running apple to what ever user set up the crontab. The second example will write everything that apple prints to STDOUT to apple.results and the last example will write erverything printed to STDERR & STDOUT to that file.
Avatar of Dartagnan324

ASKER

So 20 9 * * 6 /usr/local/apple >> myfile will create a new file named "myfile" containing the data that ./apple usually outputs?

Do I need to worry about permissions?

Thx!
>> myfile will create myfile if it doesnt exist and write the data that ./apple normally does. If the file already exists, ./apples data will be apended to it. If you want to overwrite the file every time just use 1 > instead of 2. Your permissions should be ok as long as the user who owns the crontab entry has write access to the directory myfile will be created in.
hmm.....I just tested 55 10 * * 4 /usr/local/apple >> myfile and it gives Usage: /usr/local/apple [logfile] rather than the output i usually get.  How do you fix this?

Thx!
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
Thanks a lot!