Topic
5 replies Latest Post - ‏2009-02-20T19:47:53Z by enriqueaco
SystemAdmin
SystemAdmin
232 Posts
ACCEPTED ANSWER

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
    ACCEPTED ANSWER

    Re: How to script a continuous loop

    ‏2006-07-04T04:06:00Z  in response to SystemAdmin
    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
    ACCEPTED ANSWER

    Re: How to script a continuous loop

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

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

      Re: How to script a continuous loop

      ‏2007-08-31T13:49:30Z  in response to SystemAdmin
      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
        ACCEPTED ANSWER

        Re: How to script a continuous loop

        ‏2007-09-02T20:53:19Z  in response to SystemAdmin
        Hi,

        To avoid up to 100% cpu user usage:

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

          Re: How to script a continuous loop

          ‏2009-02-20T19:47:53Z  in response to SystemAdmin
          This idea is a good solution for a good performaced.

          Greetings