LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-18-2006, 11:03 PM   #1
dwarf007
Member
 
Registered: Sep 2004
Location: Malaysia
Posts: 181

Rep: Reputation: 30
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
 
Old 07-18-2006, 11:20 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 164Reputation: 164
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
 
Old 07-18-2006, 11:27 PM   #3
dwarf007
Member
 
Registered: Sep 2004
Location: Malaysia
Posts: 181

Original Poster
Rep: Reputation: 30
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
 
Old 07-18-2006, 11:30 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 124Reputation: 124
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.
 
Old 07-19-2006, 12:04 AM   #5
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 164Reputation: 164
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.
 
Old 07-19-2006, 12:09 AM   #6
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 68
Duplicate access is needed to prevent abuse. If changing to /etc/Testing/ fails we don't want to run scripts.pl in / .
 
Old 07-19-2006, 12:24 AM   #7
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 124Reputation: 124
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.
 
Old 07-19-2006, 03:50 AM   #8
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 68
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.
 
  


Reply


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 Job Question tarballed Linux - Newbie 4 06-20-2006 03:39 PM
Cron Job Question abhijeetudas Linux - Software 2 03-01-2006 11:27 PM
crond problem,after success run the job,will mailto root singying304 Linux - Software 1 11-29-2005 05:33 PM
crond job to remove files Niceman2005 Linux - Newbie 2 01-25-2005 09:54 PM
Quick Question about cron job andy18 Linux - General 2 08-11-2003 04:16 PM


All times are GMT -5. The time now is 11:31 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration