LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   question on crond job (https://www.linuxquestions.org/questions/linux-newbie-8/question-on-crond-job-465377/)

dwarf007 07-18-2006 11:03 PM

question on crond job
 
I have some question ask regarding to cron,

Code:

*/5 * * * * ( cd /etc/Testing; /etc/Testing/scripts.pl)
My questions:
- What is the purpose of using bracket ()
- why use */5
- why access to the folder twice?
( cd /etc/Testing; /etc/Testing/scripts.pl)

Anyone can help? thanks

gilead 07-18-2006 11:20 PM

I hope my memory isn't faulty here...

Using the () groups the commands so that cron sees them as the command part of the line. They will run in the one sub-shell.

*/5 in your example means every 5 minutes.

You shouldn't need to access the folder twice, the following should work:
Code:

*/5 * * * * ( cd /etc/Testing; ./scripts.pl)
I'd even suggest just running the following unless scripts.pl can't tell what directory it's in:
Code:

*/5 * * * * /etc/Testing/scripts.pl

dwarf007 07-18-2006 11:27 PM

Thanks gilead

By the way, what do you mean by

Code:

Using the () groups the commands so that cron sees them as the command part of the line. They will run in the one sub-shell.
Do you mean, using () the systems will recognize it as run in a line even there is few rows of it?

I agree with you for the below,
Code:

*/5 * * * * /etc/Testing/scripts.pl
I dont know why the vendor is doing duplication :D

Matir 07-18-2006 11:30 PM

The parenthesis prevents cron from launching a separate subshell for each part: so that the script sees the cd. Some scripts may get a configuration file from their working directory, hence the need for the cd.

gilead 07-19-2006 12:04 AM

Quote:

Originally Posted by dwarf007
Do you mean, using () the systems will recognize it as run in a line even there is few rows of it?

Yes, that's exactly right.

P.S. Thanks to Matir for clarifying what was happening.

raskin 07-19-2006 12:09 AM

Duplicate access is needed to prevent abuse. If changing to /etc/Testing/ fails we don't want to run scripts.pl in / .

Matir 07-19-2006 12:24 AM

Quote:

Originally Posted by raskin
Duplicate access is needed to prevent abuse. If changing to /etc/Testing/ fails we don't want to run scripts.pl in / .

Actually, it will attempt to run scripts.pl in either case, but will fail unless there is a scripts.pl in crond's working directory. Replacing the ; with && would prevent crond from even thinking about running scripts.pl.

raskin 07-19-2006 03:50 AM

Well, it will try to run /etc/Testing/scripts.pl (with no luck), rather than ./scripts.pl in crond's working dir, that's what I meant. Surely, && is also an option, but if crond job works, I guess it won't be touched.


All times are GMT -5. The time now is 02:10 AM.