Help needed to Keep calling a function after every 5 seconds.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help needed to Keep calling a function after every 5 seconds.
# 1  
Old 03-25-2008
Question Help needed to Keep calling a function after every 5 seconds.

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.
# 2  
Old 03-25-2008
MySQL

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
# 3  
Old 03-25-2008
MySQL

Thanks! I had used a infinte while loop, but was trying to avoid it. I would use this method.

Thanks a lot!!
# 4  
Old 03-25-2008
Quote:
Originally Posted by nua7
I had used a infinte while loop, but was trying to avoid it.
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).
# 5  
Old 03-25-2008
Thanks era! I am planning to put the script in crontab too!

Thanks all!
nua7
# 6  
Old 03-25-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help to Modify File Name in each function before calling another function.

I have a script which does gunzip, zip and untar. Input to the script is file name and file directory (where file is located) I am reading the input parameters as follows: FILENAME=$1 FILEDIR=$2 I have created 3 functions that are as follows: 1) gunzip file 2) unzip file... (2 Replies)
Discussion started by: pinnacle
2 Replies

2. Shell Programming and Scripting

Function is calling only once

In my prog if i enter the input for the 1st time it is executing correctly, but for the second time entire script is not executing it just exiting my code is #!/bin/sh checkpo() { echo "Checking the entered PO to create output text file "; IFS=$'\n' set -f var=0 for i in $(cat... (3 Replies)
Discussion started by: Padmanabhan
3 Replies

3. Shell Programming and Scripting

Calling two function

Hi, I need to run start_load function for two tables. Step 1: if HMAX_TBL_ID and GMAX_TBLI_D are same for tab_name1 then echo message "all table ids are processed" Step 2: go back and call start_load for tab_name2 and check if table id are same for table 2 too. Please let me know how to... (5 Replies)
Discussion started by: sandy162
5 Replies

4. UNIX for Dummies Questions & Answers

Getting a error while calling a function

Hi Friends, While calling a function in below scipt func_serv_logs () { find . -type f \( \( -name 'WLS*' -o -name 'access*' \) -a ! -name '*.gz' -a ! -newer ${REFERENCE} \) -print | while read FILENAME do echo "hi" done } func_serv_logs I am getting error... (4 Replies)
Discussion started by: Jcpratap
4 Replies

5. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

6. Shell Programming and Scripting

Return a value from called function to the calling function

I have two scripts. script1.sh looks -------------------------------- #!/bin/bash display() { echo "Welcome to Unix" } display ----------------------------- Script2.sh #!/bin/bash sh script1.sh //simply calling script1.sh ------------------------------ (1 Reply)
Discussion started by: mvictorvijayan
1 Replies

7. Shell Programming and Scripting

Help needed in function calling in a script

:confused:Hi , I have a script as shown below: rpttxt() { name="$*" awk '/'"${name}"'/ {print $2 $3"=" $4}' file.txt } xx = rpttxt "COL_HEAD_1" awk 'BEGIN {printf("%36s \n ","'"$xx"'")}' rpttxt() is a function..I want to store the final result of this function in... (3 Replies)
Discussion started by: jisha
3 Replies

8. UNIX for Dummies Questions & Answers

Calling a function

I have created a file generic.func and it has lots of functions. One of the functions is this: Check_backup_size() { dsmc q b $BACKUP_DIR/"*.Z" | awk '{print $1}'|sed 's///g' > outputfile X=`awk '{sum += $1} END {print sum }' outputfile'` echo "$X" ls -ltr $BACKUP_DIR/"*.Z" | awk... (5 Replies)
Discussion started by: ashika
5 Replies

9. Programming

c++ calling main() function

i just finished a project for a c++ class that i wrote at home on my computer, compiled with gcc. when i brought the code into school it would not compile, it would complain that cannot call main() function. at school we use ancient borland c++ from 1995. anyway my program has 20 different... (3 Replies)
Discussion started by: norsk hedensk
3 Replies

10. UNIX for Dummies Questions & Answers

calling a c function from shell

Is it possible to call a C function from within a shell script. This C function is part of an API. What do I need to make it work from my shell script. Anybody please help. (4 Replies)
Discussion started by: seshagiri
4 Replies
Login or Register to Ask a Question