IC5Notice: We have upgraded developerWorks Community to the latest version of IBM Connections. For more information, read our upgrade FAQ.
Topic
  • 5 replies
  • Latest Post - ‏2009-02-20T19:47:53Z by enriqueaco
SystemAdmin
SystemAdmin
232 Posts

Pinned topic How to script a continuous loop

‏2006-06-11T16:29:19Z |
I need to create a script that continually loops. I don't want to use cron to keep re-running a script, but I need a script that I can run from a command line that will continually loop until it is terminated.

Please can I get some suggestions as to how I can accomplish this?

Thanks
Updated on 2009-02-20T19:47:53Z at 2009-02-20T19:47:53Z by enriqueaco
  • Chandru
    Chandru
    1 Post

    Re: How to script a continuous loop

    ‏2006-07-04T04:06:00Z  
    Hello Milskin

    My understanding about your problem is here.You need to run a script until it terminates not by any session or user logout... If my understanding is wrong leave this...

    To achieve this
    use
    nohup <cmd> <options>
    for more info. see man pages.

    Thanks,
    Chandru.
  • SystemAdmin
    SystemAdmin
    232 Posts

    Re: How to script a continuous loop

    ‏2007-02-14T16:21:43Z  
    or if it has to loop infinetly...how about..

    while 1 ; do <command>; done
  • SystemAdmin
    SystemAdmin
    232 Posts

    Re: How to script a continuous loop

    ‏2007-08-31T13:49:30Z  
    or if it has to loop infinetly...how about..

    while 1 ; do <command>; done
    Or you can combine both ideas:

    1. !/usr/bin/ksh
    2. Script name: loop_for_ever.sh

    while true ; do echo $(date); done



    Then you can call it like this:

    nohup ./loop_for_ever.sh &



    So now nohup makes it immune to hang-ups and the ampersand (&) makes it a backgroud process so you can have use of the shell window again.

    -Reuben
  • SystemAdmin
    SystemAdmin
    232 Posts

    Re: How to script a continuous loop

    ‏2007-09-02T20:53:19Z  
    Or you can combine both ideas:

    1. !/usr/bin/ksh
    2. Script name: loop_for_ever.sh

    while true ; do echo $(date); done



    Then you can call it like this:

    nohup ./loop_for_ever.sh &



    So now nohup makes it immune to hang-ups and the ampersand (&) makes it a backgroud process so you can have use of the shell window again.

    -Reuben
    Hi,

    To avoid up to 100% cpu user usage:

    while true ; do echo $(date); sleep 5; done
  • enriqueaco
    enriqueaco
    1 Post

    Re: How to script a continuous loop

    ‏2009-02-20T19:47:53Z  
    Hi,

    To avoid up to 100% cpu user usage:

    while true ; do echo $(date); sleep 5; done
    This idea is a good solution for a good performaced.

    Greetings