![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| calling function inside awk | jisha | Shell Programming and Scripting | 2 | 04-14-2008 04:44 AM |
| Help needed in function calling in a script | jisha | Shell Programming and Scripting | 3 | 01-15-2008 03:48 AM |
| Calling a function | ashika | UNIX for Dummies Questions & Answers | 5 | 09-12-2006 04:58 PM |
| Calling other file function | maldini | Shell Programming and Scripting | 3 | 08-18-2005 11:23 PM |
| c++ calling main() function | norsk hedensk | High Level Programming | 3 | 01-22-2003 04:28 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Hey guys.!
Need some help.I want to write a script , which should be continuosly running and should keep calling a function after every say 5 or 10 seconds. I am done with almost all part of it, but figuring out how to keep the script continuosly running and how to keep calling a function after every 5 seconds. Any help would be appreciated. |
| Forum Sponsor | ||
|
|
|
|||
|
Try the following:
func() { echo "you are in function" sleep 5 func } This function will call itself itself again and again with a time delay of 5 sec. Or if you want to call the function directly from main you can use any infinite loop i.e for/while etc with atime delay of 5 secs. Regards, Yogi |
|
|||
|
Why? A program which is supposed to keep on running forever sounds like the basic example of when you might need an infinite loop.
You might want to have a "guardian" cron job to verify that the process is always running. In case of resource exhaustion or something, the OS might kill off long-running processes (especially the infamously aggressive "oom-killer" in recent versions of Linux). |
|
|||
|
Also for a very long-running process, make sure it's not slowly hogging resources. Based on a brief test with Bash on Ubuntu Linux, the tail recursion suggested above will slowly eat up more and more memory. I'd definitely suggest an infinite loop instead.
|
|
|||
|
sure era.. This is something that I came up with (Sample code , since I cannot put in the actual code here..)
Please let me know if you have any suggestions in this. Code:
#!/usr/bin/bash
#This is a sample watch dog script.
#This would test if script1 is running,if it is not running
#it would start the script.
#function to start script1
function startscr1
{
sh /home/nua7/script1
print "Script 1 is starting"
exit 1
}
function chkscr1
{
cnt=`ps -ef | grep script1 | grep -v grep | wc -l`
if [[ $cnt -ne 1 ]]; then
startscr1
fi
}
wrapper=`ps -ef | grep wrapper | grep -v grep | wc -l`
if [[$wrapper -lt 1]];then
while true;do
chkscr1
done
|
|||
| Google The UNIX and Linux Forums |