Shell Script Run on Every Second


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script Run on Every Second
# 1  
Old 12-03-2008
Shell Script Run on Every Second

I would like to write a program that run every second.

In this program, I would retrieve data from a SQL db
and redirect the firefox to the appropriate place if the checking of SQL is success

As I really consider the performance and complexity of coding, is shell script a good choice? or other programming like Java would be better?

Thanks for any suggestions or comment.
# 2  
Old 12-04-2008
then you better cron that job
# 3  
Old 12-04-2008
Quote:
Originally Posted by uativan
I would like to write a program that run every second.

In this program, I would retrieve data from a SQL db
and redirect the firefox to the appropriate place if the checking of SQL is success

As I really consider the performance and complexity of coding, is shell script a good choice? or other programming like Java would be better?

Thanks for any suggestions or comment.
try sleep command to sleep for a particular amount of time and then start again or schedule the script in cron tab to run as you want it.
# 4  
Old 12-04-2008
Thank you for both replies

1. cron job cannot be executed in seconds, minimum is 1 minute

2. I tried to use sleep command, but I have a question

while [condition]
<<my command>>
sleep 1
do

1) if the command executes in 0.5s the total time for one process would be 1.5s?
2) And the execute time should be undetermined, the total time of each execute may be 1.5s, 1.8s, etc...?
# 5  
Old 12-04-2008
True with regards to what you said about cron. To work around that you can setup a cron to execute that script every minute. Within the script you might have something like:

command
sleep 10
command
sleep 10

^^etc. etc. You can change the frequency of course but something like that should work. Java would be less resource intensive for the server since it's client based. I'm not a big fan of java but I would try both on a test box or whatever then make my determination from there.

-- edited

oops...
missed the part about the frequency you posted and can now see why you asked about java. But going back to what you were asking:

Quote:
1) if the command executes in 0.5s the total time for one process would be 1.5s?
2) And the execute time should be undetermined, the total time of each execute may be 1.5s, 1.8s, etc...?
Keep in mind that it's not one process but two seperate processes. One for the command while another for sleep. So in theory, (better to let one of the vets here confirm), you might see two or three executing at the same time during top. If you're on shared then you may want to go with java to keep your host from nagging you about using up all of the servers resources. Lastly, if you're sql server is on another host, take into consideration what might happen if that server starts to lag drastically. You will need to keep tabs on the execution times from within the sql logs.

Last edited by phpfreak; 12-04-2008 at 01:49 AM..
# 6  
Old 12-04-2008
Thank you for your replySmilie
I will test the result of sleep command
# 7  
Old 12-04-2008
building on the first example to run a script every minute, something like this maybe?
Code:
while 1;
do
    first=`date +%s`
    exec_script &
    while 1;
        do second=`date +%s`
            result=`expr $second - $first`
            if `expr $result > 1` 
                 break;
        done;
done;

I'm not sure about the syntax though
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

To run a local shell script in a remote machine by passing arguments to the local shell script

I need to run a local shell script on a remote machine. I am able to achieve that by executing the command > ssh -qtt user@host < test.sh However, when I try to pass arguments to test.sh it fails. Any pointers would be appreciated. (7 Replies)
Discussion started by: Sree10
7 Replies

3. Shell Programming and Scripting

Run SQL thru shell script: how to get a new line when run sql query?

Hi, this's Pom. I'm quite a new one for shell script but I have to do sql on shell script to query some information from database. I found a concern to get a new line...When I run my script, it retrieves all data as wondering but it's shown in one line :( What should I do? I'm not sure that... (2 Replies)
Discussion started by: Kapom
2 Replies

4. Shell Programming and Scripting

[How To?] Run shell script and get output into another shell.

Hi guys, I have a simple question, I want to store the output of the following command: As you can see it is running all the time, and we get a new line every 3sec. I just want to store these new lines into a single variable, so I can use it into a script. To clear the screen, and... (4 Replies)
Discussion started by: Thireus
4 Replies

5. Shell Programming and Scripting

Run a shell script from one host which connext to remote host and run the commands

I want to write a script which would run from one host say A and connect to other remote host B and then run rest of commands in that host. I tried connecting from A host to B with SSH but after connecting to host B it just getting me inside Host B command prompt. Rest of the script is not running... (6 Replies)
Discussion started by: SN2009
6 Replies

6. Shell Programming and Scripting

How to run cmds after changing to a new env (shell) in a shell script

Hi, I am using HP-UNIX. I have a requirement as below I have to change env twice like: cadenv <env> cadenv <env> ccm start -d /dbpath ccm tar -xvf *.tar ccm rcv .... mv *.tar BACKUP but after I do the first cadenv <env> , I am unable to execute any of the later commands . ... (6 Replies)
Discussion started by: charlei
6 Replies

7. Shell Programming and Scripting

Help need to make a shell script run for ffmpeg vhook watermaking in shell

i have a small problem getting a batxh shell script to run in shell this is the code the problem seems to be centered around the ffmpeg command, something maybe to do with the ' ' wrapping around the vhook part command this is a strange problem , if i take the ffmpeg command and... (1 Reply)
Discussion started by: wingchun22
1 Replies

8. Shell Programming and Scripting

How to Run a shell script from Perl script in Parent shell?

Hi Perl/UNIX experts, I have a problem in running a shell script from my perl script (auto.pl). I run the perl script using perl auto.pl from the shell prompt The shell script picks the files in "input" folder and procesess it. The shell script blue.sh has this code. export... (16 Replies)
Discussion started by: hifake
16 Replies

9. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies
Login or Register to Ask a Question