The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
a cron job needs a perl script to execute Exader UNIX for Dummies Questions & Answers 2 04-22-2008 03:45 PM
Cron job -- to execute at every first Sunday of every month shanemcmahon UNIX for Dummies Questions & Answers 2 05-03-2007 11:34 PM
Need to execute 2 scripts, wait, execute 2 more wait, till end of file halo98 Shell Programming and Scripting 1 08-01-2006 04:42 PM
How to execute scripts at logout? pcsaji Shell Programming and Scripting 1 03-27-2006 06:01 AM
How can I execute TCL scripts in HP-UX wilsonchan1000 UNIX for Dummies Questions & Answers 3 03-24-2003 11:32 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-22-2007
Annorax's Avatar
Annorax Annorax is offline
Registered User
  
 

Join Date: Jun 2007
Location: MA, USA
Posts: 3
Smile CRON job to execute all scripts in a directory

Hi everyone:

I'm trying to make a CRON job that will execute Fridays at 7am. I have the following:

* 7 * * 5 [command]

I've been studying up on CRON and I know to have this in a file and then "crontab filename.txt" to add it to the CRON job list.

The CRON part I believe I understand, but I would like this job to execute all .ksh scripts in a specific folder (/usr/scripts). I'm not sure of the UNIX command to do so.

Could someone please help me with this? Thanks for any help.
  #2 (permalink)  
Old 06-22-2007
jgt jgt is offline
Registered User
  
 

Join Date: Apr 2007
Location: 44.21.48N 80.50.15W
Posts: 450
Create a script like:

#!/bin/ksh
cd /usr/scripts
list=`ls *.ksh`
for script in $list
do
$script
done

Don't forget that the path in cron is not likely to be the same as your login shell.
  #3 (permalink)  
Old 06-22-2007
harmonwood harmonwood is offline
Registered User
  
 

Join Date: Jun 2007
Location: Texas
Posts: 10
You could write a script like this:
Code:
#!/bin/bash
dir="/file/to/scripts/"
for file in $dir
do
   $file
done

Last edited by reborg; 06-22-2007 at 12:48 PM..
  #4 (permalink)  
Old 06-22-2007
Annorax's Avatar
Annorax Annorax is offline
Registered User
  
 

Join Date: Jun 2007
Location: MA, USA
Posts: 3
Thank you all for the help. Not all of the files in the script directory are scripts, so the first script would probably suit me better.

Please forgive my "newbie-ness", but let me just double check things:

1.) I have a text file scriptCron.txt with this in it:

* 7 * * 5 /home/oracle/executeScripts.sh

2.) I have the executeScripts.sh file chmod'd to 777 and containing this:

#!/bin/ksh
cd /home/oracle/scripts
list=`ls *.ksh`
for script in $list
do
$script
done

3.) All I need to do is "crontab scriptCron.txt" and then it should be added to the crontab list.

And that should be it.

Does the user have to be logged in for the CRON jobs to run or will it run automatically?

Thanks again for the help.
  #5 (permalink)  
Old 06-22-2007
jgt jgt is offline
Registered User
  
 

Join Date: Apr 2007
Location: 44.21.48N 80.50.15W
Posts: 450
No the user does not have to be logged in.
Also be aware that stdin and stdout do not exist, so if any of your scripts expect input that input should be pre-set in a file, and any output should be redirected to a file.
  #6 (permalink)  
Old 06-22-2007
hemangjani hemangjani is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 73
Annorax,

- A user does not have to be logged in for the cron to run.

- You do not need to have a *.txt file and pass it to crontab.
Run:
=> crontab -e

And you can edit the crontab file.

  #7 (permalink)  
Old 06-22-2007
hemangjani hemangjani is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 73
Smile

An easy way would be:

=> crontab -l
* 7 * * 5 /home/annorax/cronscript



=> vi /home/annorax/cronscript

/usr/scripts/script_1
/usr/scripts/script_2
/usr/scripts/script_3
...
...
...
/usr/scripts/script_n
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0