Solved

Perl cron jobs

Posted on 2004-03-24
7
364 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS- KeepAlived notify script not working 23 103
mcrypt_create_iv() is deprecated 4 279
looking for a CENTOS ISO to download with x window installed 2 50
Apache module 5 45
How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

840 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