Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Perl cron jobs

Posted on 2004-03-24
7
Medium Priority
?
369 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 240 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
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
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 160 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

722 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