Solved

Perl cron jobs

Posted on 2004-03-24
7
367 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
[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
  • 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

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

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

615 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