LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   adding a perl script to cron.daily / cron.d to setup a cron job (https://www.linuxquestions.org/questions/linux-software-2/adding-a-perl-script-to-cron-daily-cron-d-to-setup-a-cron-job-592762/)

CrontabNewBIE 10-18-2007 10:01 AM

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.

thebouv 10-18-2007 11:13 AM

Quote:

Originally Posted by CrontabNewBIE (Post 2928521)
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

CrontabNewBIE 10-18-2007 02:12 PM

so no additions are required to the cron.daily or cron.d folders under /etc?

thebouv 10-19-2007 11:38 AM

Quote:

Originally Posted by CrontabNewBIE (Post 2928793)
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.

WhyWontThisWork 01-12-2008 01:21 AM

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?

thebouv 01-13-2008 01:36 PM

minute hour dayofmonth month dayofweek

man crontab for more info

CrontabNewBIE 01-14-2008 08:16 AM

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

We can now let this thread die.

Thanks again!


All times are GMT -5. The time now is 05:26 AM.