scripting running every minute


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting scripting running every minute
# 8  
Old 12-30-2008
Quote:
Originally Posted by vgersh99
sorry, I must be thick-sculled - I'm having hard time parsing this sentence.
Chris, could you elaborate a little bit more and why your other suggestion is any better.
In 2 words or less.....

Code:
while :
do
  : command takes XX seconds to execute
  sleep 60
done

The command will be run every 60 + XX seconds.

Code:
while :
do
  sleep 60 & pid=$!  ## sleep runs in the background
  : command takes XX seconds to execute
  wait $pid          ## wait for sleep to exit
done

So long as the command takes less than 60 seconds, it will be run exactly every 60 seconds.
# 9  
Old 12-30-2008
my bad - you're absolutely right. Somehow I thought that the original 'some_command' was being spawned in the background as well. Sorry - too much egg-nock I reckon.

But at the same time....
Code:
while :
do
    sleep 60 & pid=$!
    some_command arg1 arg2
    wait $pid
done

if 'some_command' takes longer than 60 sec to run, this implementation is not the same as it would have been if cron-ed.
But if we put the 'some_command' in the background, it would be the same.
Not sure what the OP's intentions are though.

thanks for pointing to the obvious!
# 10  
Old 12-31-2008
Cool! Cfajohnson, you taught me two new things here. However,

Quote:
Originally Posted by cfajohnson
There's no need for screen. Use nohup and put it in the background.
While I am pleased to learn about the nohup command, I still contend that the screen command is extremely valuable. If the command being executed spits out anything interesting, you may not want it emailed to you every minute, but if you let it go to the screen, you can view it from any computer you can ssh from.

I've used screen a couple times to start a bit-torrent download of a large .iso file on my home computer while I was at work. It's nice to be able to leave it running in the terminal while the terminal is floating unattached and then to be able to reattach it to take a look from any computer at home or work.
# 11  
Old 12-31-2008
I could completely attach and detach a session as I wish with a 'screen' and that's not possible with nohup in background
# 12  
Old 12-31-2008
Quote:
if 'some_command' takes longer than 60 sec to run, this implementation is not the same as it would have been if cron-ed.
Why? I don't quite understand that.

lets take 'some_command' takes 120 secs to run ( > 60 ) and in this case ( sample posted in the thread ), wait - waiting for $! will be activated and once again its back in the 'while' loop

same is the case for a cron-d
it doesn't check whether previous instance instantiated has completed or not, its job is to spawn instance every 'n'th minute.

Code:
end of 1st minute - one instance will be running
end of 2nd minute - first instance will be terminated
                            second instance started
end of 3rd minute - second instance still running
                           third instance spawned

and so on ...

why do you think there is a difference ?
# 13  
Old 12-31-2008
Quote:
Originally Posted by matrixmadhan
Why? I don't quite understand that.

lets take 'some_command' takes 120 secs to run ( > 60 ) and in this case ( sample posted in the thread ), wait - waiting for $! will be activated and once again its back in the 'while' loop



[/CODE]
why do you think there is a difference ?
first of all i would like congratulate for participating this thread and made your own valuble opinoin. I am really impressed and heading to get a proper solution.

I just want to know in the below code- pid=$i --> what exactly means by that? I will then implement it in my systme.
Code:
while :
do
    sleep 60 & pid=$!
    some_command arg1 arg2
    wait $pid
done

as the above code work as same like cron-d means if som_command take more than 60 second to execute meanwhile whithin 60 seconds some_command will again execute.
# 14  
Old 12-31-2008
dear experts,

i run the below whileloop script--
$whileloop.sh &

#!/usr/bin/bash --> i did Not use this noe as header

Code:
while :
do
  sleep 60 & pid=$!
 /export/home/scripts/finding_txt_TXT_files_and_execute.sh
  wait $pid
done

for time being i now wanted to stop the whileloop.sh procss. I tried get the process id to kill it. becuase every 60 seconds it comes live...

i tried ps -ef | grep whileloop but did not find. Is there any other command to find the background process.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Minute(4) issue in teradata

I have values below for which diff field is giving error like "invalid time interval" in teradata Might be it is not doing calculation anymore after exceeding minute(4) value END_TS 2/2/2018 08:50:49.000000 START_TS 1/5/2018 17:30:02.000000 SLA_TIME 23:59:59.000000 select... (0 Replies)
Discussion started by: himanshupant
0 Replies

2. UNIX for Beginners Questions & Answers

How to display only the first 5 running process using top in shell scripting?

topfunc() { top } topfunc Here i used the top command inside a function,and i called the function. when executing this bash file i get all the process which are using by the kernel i just want to display only the first 5 running process. is it possible? (7 Replies)
Discussion started by: Meeran Rizvi
7 Replies

3. UNIX for Dummies Questions & Answers

Need record count on every 30 minute

We have the below records where we need record count of every 30 minute like 00:01 to 00:30 so in that we will have 48 record count in 24 hrs , and also we need sum of record count from 00:01 to 23:30. Please find sample data as well. 00:01 21 00:02 23 00:03 34 00:04 34 00:05 30... (10 Replies)
Discussion started by: nadeemrafikhan
10 Replies

4. Shell Programming and Scripting

Shell scripting issue-running the background script

I have written the below query to genrate a telephone.I am passing account number from oracle database. I am calling 2 scripts which generate the bill 1. bip.sh (it runs in the background) 2.runXitInvoice_PROFORMA_integ bip.sh generates a number which runXitInvoice_PROFORMA_integ uses.How... (7 Replies)
Discussion started by: rafa_fed2
7 Replies

5. Shell Programming and Scripting

Take minute per minute from a log awk

Hi, I've been trying to develop a script that performs the parsing of a log every 1 minute and then generating some statistics. I'm fairly new to programming and this is why I come to ask if I can lend a hand. this is my log: xxxx 16/04/2012 17:00:52 - xxxx714 - E234 - Time= 119 ms.... (8 Replies)
Discussion started by: jockx
8 Replies

6. Shell Programming and Scripting

Crontab for every minute or every hour

How to set crontab for every minute or every hour (1 Reply)
Discussion started by: kaushik02018
1 Replies

7. Shell Programming and Scripting

How do i get only last 5 minute worth of data

I have a text file called 'tomcat_temp_out'. I want to get only last 5 minute worth of data from this file and redirect those data into another fule. Could you please help to work on this? (2 Replies)
Discussion started by: shivanete
2 Replies

8. UNIX for Dummies Questions & Answers

perl scripting for checking if a process is running

Hi All, I am new to perl and have been trying to write a short script to check a process.Though i havent reached to the stage where i can match the output. I am trying to pass a variable x with value /opt/RGw/csbp-base/CSBP_BAT.01.00.05/csbp_BAT.01.00.05.jar and then pass another variable... (2 Replies)
Discussion started by: pistachio
2 Replies

9. Solaris

syslog messages every minute

Hi If we have for example a disk that is experiencing problems, ie read errors etc, a message will get generated via syslog every one minute....I come in the morning to hundreds upon hundreds of the same message. Is there anyway to change this to say 5 minutes or maybe 10 mins etc so that it... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

10. Programming

linux 7.1 goes off every other minute

i have loaded linux 7.1 on my PC along with win98 the problem is that every other minute th system goes off please help me (1 Reply)
Discussion started by: vidya_harnal
1 Replies
Login or Register to Ask a Question