LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 10-18-2007, 11:01 AM   #1
CrontabNewBIE
LQ Newbie
 
Registered: Oct 2007
Posts: 5

Rep: Reputation: 0
Unhappy adding a perl script to cron.daily / cron.d to setup a cron job


Hello,

This is my first post here, I'm practically new to crontabs. I have understood the basic method of writing crontabs and executing them.

I need help figuring out how to add a perl script to cron.daily/cron.d scripts. I have looked in all older questions in Forums, but couldn't find the correct method of calling this and having it run at a certain time of the day.

Can someone please explain to me how to accomplish the following:

1. I have a perl script that does a mysqldump. The script works from the command line. script at the following location:
Code:
/auto_home/userid/scripts/testdump.pl
I have tried executing it like so:
Code:
shell>/auto_home/userid/scripts/testdump.pl
2.There are two directories in /etc/ .. cron.d and cron.daily. From what I have read in all other posts is this: if logged in as root, add the script to cron.daily or if logged in as user, add the script to cron.d

3. My question is: how do i add a perl script to any one directory? Just add a file to the relevant directory with the same name as the script and what do I put in this file? a simple absolute path to the script or does it need anything else?

4. Also, how do I specify the time to run? I would like to test this before setting this up as root and adding it to cron.daily so that it runs at the time given in crontab run-parts. Do I specify the file name under cron.d in crontab -e and will it will? Any syntax that I need to add it in other than
Code:
10 12 18 10 * root /etc/cron.d/file_name
? Also, how do I get the output copied to my directory under auto_home/? Seems like root doesn't have access to write to my dir.

Please help.
 
Old 10-18-2007, 12:13 PM   #2
thebouv
Member
 
Registered: Aug 2007
Distribution: RHEL, Fedora, Ubuntu
Posts: 64

Rep: Reputation: 16
Quote:
Originally Posted by CrontabNewBIE View Post
Hello,
2.There are two directories in /etc/ .. cron.d and cron.daily. From what I have read in all other posts is this: if logged in as root, add the script to cron.daily or if logged in as user, add the script to cron.d
Eh, no. Use cron.daily for things you want root to do (maintenance scripts, etc). cron.d use is explained, to quote: "In Debian and Redhat cron treats the files in /etc/cron.d as extensions to the /etc/crontab file (they follow the special format of that file, i.e. they include the user field). The intended purpose of this feature is to allow packages that require finer control of their scheduling than the /etc/cron.{daily,weekly,monthly} directories allow to add a crontab file to /etc/cron.d."

In other words, you're not using it correctly.

Quote:
3. My question is: how do i add a perl script to any one directory? Just add a file to the relevant directory with the same name as the script and what do I put in this file? a simple absolute path to the script or does it need anything else?
You can leave your Perl script where it is.

Quote:
4. Also, how do I specify the time to run? I would like to test this before setting this up as root and adding it to cron.daily so that it runs at the time given in crontab run-parts. Do I specify the file name under cron.d in crontab -e and will it will? Any syntax that I need to add it in other than
Code:
10 12 18 10 * root /etc/cron.d/file_name
? Also, how do I get the output copied to my directory under auto_home/? Seems like root doesn't have access to write to my dir.
Do the following:

1) Edit your personal crontab via: crontab -e (do this as your user, not as root).

2) Add this line: 10 12 18 10 * /auto_home/userid/scripts/testdump.pl

3) Save.

4) Make sure testdump.pl is chmod'd to 755 of course.

5) To get the output of your Perl script, make #2 this instead:

10 12 18 10 * /auto_home/userid/scripts/testdump.pl > /auto_home/path/yourfileblahblah.txt
 
1 members found this post helpful.
Old 10-18-2007, 03:12 PM   #3
CrontabNewBIE
LQ Newbie
 
Registered: Oct 2007
Posts: 5

Original Poster
Rep: Reputation: 0
so no additions are required to the cron.daily or cron.d folders under /etc?
 
Old 10-19-2007, 12:38 PM   #4
thebouv
Member
 
Registered: Aug 2007
Distribution: RHEL, Fedora, Ubuntu
Posts: 64

Rep: Reputation: 16
Quote:
Originally Posted by CrontabNewBIE View Post
so no additions are required to the cron.daily or cron.d folders under /etc?
Not unless you want your script to run at the same time as the cron.daily ones. And as I said above, cron.d is for additional cron config files, not for scripts themselves.

Usually, as a user, you keep the script in your directory and edit your crontab.
 
Old 01-12-2008, 02:21 AM   #5
WhyWontThisWork
LQ Newbie
 
Registered: Jan 2008
Posts: 10

Rep: Reputation: 0
questions creating the file

When i entered the command contrab -e, it opened the text editor in a file in /tmp... is that right? and m h dom mon dow mean what? is it min hour _ _ DayOfWeek?
 
Old 01-13-2008, 02:36 PM   #6
thebouv
Member
 
Registered: Aug 2007
Distribution: RHEL, Fedora, Ubuntu
Posts: 64

Rep: Reputation: 16
minute hour dayofmonth month dayofweek

man crontab for more info
 
Old 01-14-2008, 09:16 AM   #7
CrontabNewBIE
LQ Newbie
 
Registered: Oct 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Talking Got the crontab working

Thanks again for posting helpful information. I finally got this working.

We can now let this thread die.

Thanks again!
 
  


Reply

Tags
crond, crondaily, crontabs, perl, script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cron hourly, daily, cron.d jobs don't execute eggsmartha Linux - General 3 09-17-2007 07:37 PM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 02:50 PM
Errors when running Perl script in a cron job meshach Slackware 2 06-20-2006 10:10 PM
Trouble with perl script in Cron job thack111 Linux - General 7 11-25-2004 03:44 AM
dual entries in cron log for cron.daily cpharvey Linux - General 3 02-27-2003 03:30 PM


All times are GMT -5. The time now is 03:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration