Visit Our UNIX and Linux User Community

Running scripts with condition

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Running scripts with condition
# 1  
Old 01-16-2001

I have two scripts:
SCR1 which takes between 5 seconds to 15 minutes and needs to be run every 23 minutes.
SCR2 which needs to be run every 5 minutes but only if SCR1 is not running at that moment.

How can I do this task?

Best Regards
# 2  
Old 01-16-2001
The easy answer is to have SCR1 touch a lock file when it starts and delete it when it finishes. Then have SCR2 test for the presence of the lock file and exit if it exists. I am assuming you know how to schedule the jobs using crontab.

At the beginning of SCR1 below the #!/path/to/shell entry, have something like;
touch /tmp/scr1.lock

Then the last line executed should be;
rm -f /tmp/scr1.lock

At the beginning of SCR2, enter;
if [ -e /tmp/scr1.lock ]
then exit

I hope this helps
# 3  
Old 01-16-2001
I forgot a very important issue in my description of the problem. The solution you gave is very smart, good and easy to understand but the problem is that I am not allowed to modify the scripts SCR1 and SCR2.

Best Regards
# 4  
Old 01-16-2001
Then use a wrapper.
Create another script like launch.scr1;

touch /tmp/scr1.lock
rm -f /tmp/scr1.lock

And then create the wrapper for SCR2 called launch.scr2

if [ -e /tmp/scr1.lock ]
then exit
else /path/to/SCR2

Than change your cron entries to execute the wrapper scripts instead of the actual scripts/executables.

[Edited by 98_1LE on 01-16-2001 at 10:13 AM]

Previous Thread | Next Thread
Test Your Knowledge in Computers #369
Difficulty: Medium
The name bytecode originates from instruction sets that have zero-byte opcodes followed by optional parameters.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing multiple scripts using if condition

I have an if condition. If that condition is true then one script will be run and after that I need to check another condition based on the output value of first script. i tried like below : cd lock if ; then rm exitup if ; then kb_shutdown kb_startup if ; then rm exitup if ;... (3 Replies)
Discussion started by: charanarjun
3 Replies

2. UNIX for Dummies Questions & Answers

Running scripts from different server

Hi, I need a script (ksh) on ServerAdmin that will run an archive scripts from different several Servers through ssh. The problem is that how can i switch user when before running the archive script. I already configured password-less connection on the servers. server 1... (1 Reply)
Discussion started by: chococrunch6
1 Replies

3. Solaris

running scripts from cron

I need to run a script (from cron) that runs a second script. What worries me is that second script, when run from bash, upon finishing doesn't return to bash unless I press the 'Enter' key. I presume that's because last command in that script ends with & Could that be a problem for cron?... (2 Replies)
Discussion started by: orange47
2 Replies

4. Shell Programming and Scripting

Running scripts within scripts from cron

Hi all, I have set up a cron job which calls another shell script shell script which in turn calls a Java process. The cron tab looks so. 0,30 7-18 * * 1-5 /u01/home/weblogic/brp/bin/ >> /u01/home/weblogic/logs/checkstatus.log The scripts looks like this. ... (4 Replies)
Discussion started by: sirbrian
4 Replies

5. Shell Programming and Scripting

Running scripts via su

Hi All, Am using the below command to start my application using the root user su - bin -c "/home/bin/test/" but am getting the error becaue i have set some environment varibales in bin .profile when i execute the command by logging directly into bin account it's... (8 Replies)
Discussion started by: ravi.sri24
8 Replies

6. UNIX for Dummies Questions & Answers

until loop : running even if condition is satisfied

I am checking one until loop with the following logic until || |||| do sleep 30 done before running this i am exporting above variables to SUCCESS.But the loop is running in infinite loop.My requirement is to make the loop run until all the 3 variables are SUCCESS or any of the 3... (2 Replies)
Discussion started by: dr46014
2 Replies

7. Shell Programming and Scripting

Running scripts through cronjob.

Hello everybody, I'm trying to run a shell script in crontab file. But anyhow it's not getting executed. Following is the command that I've used in crontab. 30 07 * * * . ./.cronprofile;/om/reports/reportscripts/jitu/prod/ 35 11 * * * .... (3 Replies)
Discussion started by: jitu.jk
3 Replies

8. Shell Programming and Scripting

When running if condition, getting the following error

Hi All, My input file name is the contents of file are cat status2.txt | while read filename do echo "$filename" echo "first content of the file is ${filename}" echo "second content of the file is ${filename}" echo "second content of the file is ${filename}" if } -eq 0 -a... (1 Reply)
Discussion started by: sunitachoudhury
1 Replies

9. Shell Programming and Scripting

Running scripts in parallel

Hi, Iam having the scripts as follows. i jus want to run those in parallel. main aim is to minimise the time for overall execution of the script. now out.txt is having 1 lac records. script1( split -1000 out.txt splitout ls -A splitout* > filelist.txt cat filelist.txt... (6 Replies)
Discussion started by: nivas
6 Replies

10. UNIX for Dummies Questions & Answers

scripts running under different users

what command can i use to tell if a script is running under different users? (1 Reply)
Discussion started by: csnewbie
1 Replies

Featured Tech Videos