CRON job to execute all scripts in a directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers CRON job to execute all scripts in a directory
# 1  
Old 06-22-2007
Bug 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. Smilie
# 2  
Old 06-22-2007
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  
Old 06-22-2007
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 01:48 PM..
# 4  
Old 06-22-2007
Bug

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
# 5  
Old 06-22-2007
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. Smilie
# 6  
Old 06-22-2007
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.
# 7  
Old 06-22-2007
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.

Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Is there a way to restrict a user (owner) to execute scripts from a specific directory

Hello, I have a user Bob on a RHEL 7 server1. Where his script area is "/home/Bob/scripts/" and he is the owner for this directory. On the server1, there is a NFS mount from another server2, with path as "/global/work/" and Bob is the owner for this directory too in server2. (Same UID and GID... (5 Replies)
Discussion started by: karumudi7
5 Replies

2. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

3. Shell Programming and Scripting

Cron Job failure - No such file or directory

Hi all, I'm having an issue with a script i wrote to pull information from the Amazon AWS API. Basically the script takes arguments from the command line and attempts to grab user information for each AWS access group. The command is issued like this: # sh awsReport.sh <outputFileName>... (3 Replies)
Discussion started by: ChocoTaco
3 Replies

4. Shell Programming and Scripting

Adding a cron job that will execute everyday at 14:50 hrs

Hi I want to execute a cron job everyday at 14:50 hrs. I have a script like this: TMP_FILE="/tmp/tmpcron.txt" RES=0 /usr/bin/crontab -l >> $TMP_FILE ADD_JOB="50 14 * * * /opt/mypath/scriptname.sh" grep "scriptname.sh" $TMP_FILE >> /dev/null JOB_NOT_EXIST=$? if test $JOB_NOT_EXIST... (2 Replies)
Discussion started by: saurabhkoar
2 Replies

5. UNIX for Dummies Questions & Answers

Executing python scripts via cron job

Hi, I'm executing a python script via cron job. The way it is set up is, I'm editing a file called local00 22 * * * root su - -c "/opt/setup_dir/bin/run_bkp -p" When this job executes, the command-specific logfile and the syslog (where the logs are supposed to go) show half of the logs(no... (2 Replies)
Discussion started by: ashwini.engr07
2 Replies

6. Shell Programming and Scripting

cron job is not working for two scripts

Hi Gurus, I have a test unix server in which currently some unix cronjob are running. I have written two script one is a shell script in which env variable are there (in that i am exporting those variables). I have also written a perl script . when i am running at the shell manually like... (5 Replies)
Discussion started by: sanjay.login
5 Replies

7. Shell Programming and Scripting

Cron job to move file from one directory to another

Hi, I have following directory structure Media (Inside media directory I have two folders namely videos and images) -->videos -->images Inside media directory I have some video files with extension .mp4 and images with extension of .jpg and .jpeg I want to write a cron job which will... (3 Replies)
Discussion started by: tusharkale
3 Replies

8. Solaris

cron job starts new cron proccess

I run cron in solaris 10 zone. One cron job which syncing files to nfs mounted on container, creates after finishing another cron proccess(/usr/sbin/cron), and after 100 existing cron proccesses next cron job will not start. It's too weird for me, I'm not able to solve this problem. Theoretically... (3 Replies)
Discussion started by: ron76
3 Replies

9. UNIX for Dummies Questions & Answers

a cron job needs a perl script to execute

Hello evreyone, this is my first post, and to say i'm new to this is an understatement. I know very little about perl scripts and hope some one can help me. i'm looking to get a script that a cron job can execute. what the script needs to to is 1) connect to a mysql database 2) go to a... (2 Replies)
Discussion started by: Exader
2 Replies

10. UNIX for Dummies Questions & Answers

Cron job -- to execute at every first Sunday of every month

Dear all How can I schedule the cronjob to be run sometime at every first Sunday at every month? I have the edit the cronjob every month now, thanks (2 Replies)
Discussion started by: shanemcmahon
2 Replies
Login or Register to Ask a Question