Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Need help in running a script continuously non stop

Shell Programming and Scripting


Tags
shell scripting

Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-21-2013
sandeepcm sandeepcm is offline
Registered User
 
Join Date: May 2012
Last Activity: 9 April 2013, 9:29 AM EDT
Posts: 16
Thanks: 4
Thanked 0 Times in 0 Posts
Ubuntu Need help in running a script continuously non stop

Hi,

I am running a schedular script which will check for a specific time and do the job. I wanted to run this continuously. Meaning even after the if condition is true and it executes the job, it should start running again non stop.
I am using below script

Code:
#!/bin/sh
start:
while true
do
hour=$(date +"%T")
if [ "$hour" == 18:30:00 ]; then
<Do the JOB>
goto start
fi
done

The problem I am facing here is its not recognizing start command initially. So i am not able to optimise it. Can anyone help?

Last edited by vbe; 02-21-2013 at 04:33 AM.. Reason: code tags please
Sponsored Links
    #2  
Old Unix and Linux 02-21-2013
balapobi balapobi is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 24 April 2015, 3:00 AM EDT
Location: Chennai
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts

Code:
#!/bin/sh
while true
do
  hour=$(date +"%T")
  if [ "$hour" == 18:30:00 ]; then
    <Do the JOB>
  fi
done


Last edited by Franklin52; 02-21-2013 at 05:46 AM.. Reason: Code tags
Sponsored Links
    #3  
Old Unix and Linux 02-21-2013
sandeepcm sandeepcm is offline
Registered User
 
Join Date: May 2012
Last Activity: 9 April 2013, 9:29 AM EDT
Posts: 16
Thanks: 4
Thanked 0 Times in 0 Posts
Ubuntu

Quote:
Originally Posted by balapobi View Post
#!/bin/sh
while true
do
hour=$(date +"%T")
if [ "$hour" == 18:30:00 ]; then
<Do the JOB>
fi
done
The above script will stop running when the if condition becomes true. I want this to run daily at 18:30:00. So I thought of using the goto statement. But it is not helping me as we cannot give start initially.
    #4  
Old Unix and Linux 02-21-2013
Jotne's Unix or Linux Image
Jotne Jotne is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 20 September 2014, 2:08 AM EDT
Posts: 1,040
Thanks: 62
Thanked 216 Times in 204 Posts
Use crontab to make it run everyday at a certain time.

Code:
30 18 * * * /youscript.sh

Sponsored Links
    #5  
Old Unix and Linux 02-21-2013
sandeepcm sandeepcm is offline
Registered User
 
Join Date: May 2012
Last Activity: 9 April 2013, 9:29 AM EDT
Posts: 16
Thanks: 4
Thanked 0 Times in 0 Posts
Ubuntu

Quote:
Originally Posted by Jotne View Post
Use crontab to make it run everyday at a certain time.

Code:
30 18 * * * /youscript.sh

@Jotne: Can you elaborate please? I didn't quite get that. What does 30 mean in the code?
Sponsored Links
    #6  
Old Unix and Linux 02-21-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 29 July 2015, 5:33 AM EDT
Location: Aachen, Germany
Posts: 6,390
Thanks: 112
Thanked 1,762 Times in 1,648 Posts
Quote:
Originally Posted by sandeepcm View Post
The above script will stop running when the if condition becomes true. I want this to run daily at 18:30:00. So I thought of using the goto statement. But it is not helping me as we cannot give start initially.
Why should it stop - while true will stay true and thus loop forever. Which it does. It will hog CPU like mad, eventually run your 18:30h job in between...
Use Jotne's proposal and you're there.


P.S.: That START: ... GOTO START is a DOSism, I think. I guess it's unavailable in any *nix shell.
Sponsored Links
    #7  
Old Unix and Linux 02-21-2013
sandeepcm sandeepcm is offline
Registered User
 
Join Date: May 2012
Last Activity: 9 April 2013, 9:29 AM EDT
Posts: 16
Thanks: 4
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by RudiC View Post
Why should it stop - while true will stay true and thus loop forever. Which it does. It will hog CPU like mad, eventually run your 18:30h job in between...
Use Jotne's proposal and you're there.


P.S.: That START: ... GOTO START is a DOSism, I think. I guess it's unavailable in any *nix shell.
Yes RudiC. It is hogging my CPU like anything. But I didn't quite get what Jotne said.
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Run a script continuously for 10 minutes Jayaraman Shell Programming and Scripting 5 07-23-2012 01:14 PM
Shell Script to continuously scan a log file novice82 Shell Programming and Scripting 1 10-09-2009 01:03 AM
How to stop a script running in remote server from local script mannepalli Shell Programming and Scripting 1 03-04-2009 07:18 PM
How to stop the script which is running in background Prateek007 Shell Programming and Scripting 3 11-23-2008 04:54 AM
How to stop asking password while running shell script? govindts Shell Programming and Scripting 5 11-12-2008 01:40 PM



All times are GMT -4. The time now is 07:28 AM.