Solved

Perl cron jobs

Posted on 2004-03-24
7
360 Views
Last Modified: 2010-04-20
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
0
Comment
Question by:Dartagnan324
  • 3
  • 2
  • 2
7 Comments
 
LVL 17

Accepted Solution

by:
owensleftfoot earned 60 total points
ID: 10672551
20 9 * * 6 /usr/local/program.pl >> myfile
0
 
LVL 40

Expert Comment

by:jlevie
ID: 10672980
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.
0
 

Author Comment

by:Dartagnan324
ID: 10677903
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!
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Expert Comment

by:owensleftfoot
ID: 10678064
>> 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.
0
 

Author Comment

by:Dartagnan324
ID: 10678959
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!
0
 
LVL 40

Assisted Solution

by:jlevie
jlevie earned 40 total points
ID: 10680110
apple may be smart enough to determine that it isn't being run from a tty and thus is asking for a file to write its results in. Try:

55 10 * * 4 /usr/local/apple /path-to/myfile
0
 

Author Comment

by:Dartagnan324
ID: 10682171
Thanks a lot!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now