![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| default cron shell | dummy_9746 | Shell Programming and Scripting | 2 | 10-13-2008 03:25 PM |
| Cron execution of shell script | ashish.sharma | Shell Programming and Scripting | 3 | 09-08-2008 03:57 AM |
| Is it possible to have more than one Cron in shell script? | Yamini Thoppen | AIX | 4 | 12-17-2007 03:23 AM |
| Shell script & cron | deppy82 | Shell Programming and Scripting | 3 | 08-02-2007 02:00 PM |
| Shell + Oracle + Cron job | pathanjalireddy | Shell Programming and Scripting | 1 | 04-07-2005 03:07 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
which one is better Run by Cron or Shell
Dear Experts, I have a script defined in Cron which runs every 1 minute. Code:
* * * * * /export/home/myscript.sh >/dev/null 2>&1 Now the issue is executing that myscript.sh sometime will take 2/3 or more minutes to finish execution. But after 1 minute cron will invoke another instance(process) execute the myscript. In that case do you think there is a probability to overlapping the instance and may create problem. If there is a chance for overlapping may be the below shellscript(run it in background) is okay which will run every 1 minute. Script will invoke different instant after every minute. Code:
#!/usr/bin/bash
while :
do
sleep 60 & pid=$!
/export/home/myscript.sh
wait $pid
done
Could you please make your valuable suggestion? //purple |
|
||||
|
There is another solution to this problem, but you have to add some code to your `myscript.sh'. Put some kind of lock while your program is runing, e.g. if your program is a shell script, you can add the following lines: Code:
...
lock=/export/home/.myscript.lock
trap "rmdir ${lock}; exit 2" 1 2 3 15
# Now lock. If lock fails, then propably the program is runing.
mkdir ${lock} || exit 0
...
Here comes the script code
...
# Now unlock, so another instance of this program can run in the future.
rmdir ${lock}
I prefer this kind of coding in such cases, because it's better to protect this kind of programs to run overlaping processes. So, either you prefer cron, or sleeping nohup shell scripts, the process is vulnerable to run in simultaneus instances; if you use some kind of locking this is impossible. Bye... |
|
||||
|
Quote:
Code:
#!/usr/bin/bash
lock=/export/home/.myscript.sh.lock
trap "rmdir ${lock}; exit 2" 1 2 3 15
mkdir ${lock} || exit 0
...
Here comes my script code
...
rmdir ${lock}
After that i can put the script in Crontab. In that case every 1 minute cron will invoke process and child process. But meanwhile, the program (myscript) can be running with different process and child process id. right? //purple |
|
||||
|
moreover,
let say myscript.sh is running and having the below process id- solaris:/home/user1> ps -ef|grep myscript.sh solaris 25907 10427 0 14:36:50 ? 0:00 /export/home/myscript.sh i put the myscript.sh in cron as 1 minute interval. So, every 1 minute interval solaris again run the myscript.sh. DO you think solaris May try to assing the next myscript.sh with procss id 25907( which indicating overlapping)? procss id 25907 still running..... |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|