<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Looping  a script  with sleep.. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564432#M919441</link>
    <description>One more question.&lt;BR /&gt;All the options that were giving to me on this post work great.&lt;BR /&gt;But what is the difference from doing as Mr. James said with the typeset option or doing what Mr. Bezawada recommended. Or is it just personal perference. &lt;BR /&gt;&lt;BR /&gt;Richard&lt;BR /&gt;</description>
    <pubDate>Mon, 13 Aug 2001 15:57:43 GMT</pubDate>
    <dc:creator>someone_4</dc:creator>
    <dc:date>2001-08-13T15:57:43Z</dc:date>
    <item>
      <title>Looping  a script  with sleep..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564424#M919433</link>
      <description>Hello ..&lt;BR /&gt;Is there a way I can "loop" a script to run every 2 or 5 minites with a sleep with out running it from cron? I guess am looking for some kind of test statement or a times loop. To where if I run&lt;BR /&gt;./script &amp;amp; it will run in the background and execute every 2 5 minutes or whenever I want it to. If there is a way is this a good idea or not? My it director says that sometimes scripts go crazy if we run them from cron. He says: if your script goes banana for some reason cron will keep on running it &lt;BR /&gt;you could end up many many many zombies or runaway.. &lt;BR /&gt;&lt;BR /&gt;Richard</description>
      <pubDate>Sat, 11 Aug 2001 14:38:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564424#M919433</guid>
      <dc:creator>someone_4</dc:creator>
      <dc:date>2001-08-11T14:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: Looping  a script  with sleep..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564425#M919434</link>
      <description>Hi&lt;BR /&gt;   you can have something like this in the script (a.sh)&lt;BR /&gt;&lt;BR /&gt;while true ;do&lt;BR /&gt;    do your stuff&lt;BR /&gt;    sleep 300&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;  The script will do your stuff, sleep for 5 mins and then do yout stuff.....&lt;BR /&gt;&lt;BR /&gt;...BPK...&lt;BR /&gt;  and you can run the script as ./a.sh &amp;amp;&lt;BR /&gt;</description>
      <pubDate>Sat, 11 Aug 2001 14:45:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564425#M919434</guid>
      <dc:creator>Praveen Bezawada</dc:creator>
      <dc:date>2001-08-11T14:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: Looping  a script  with sleep..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564426#M919435</link>
      <description>Hi Richard:&lt;BR /&gt;&lt;BR /&gt;Here's one.  Call the script "my.sh".  This will excute a loop 10-times before terminating, pausing 3-seconds each time.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset -i I=0&lt;BR /&gt;while (( I &amp;lt; 10 ))&lt;BR /&gt;do&lt;BR /&gt;  date&lt;BR /&gt;  let I=I+1&lt;BR /&gt;  sleep 1&lt;BR /&gt;done&lt;BR /&gt;#_end&lt;BR /&gt;&lt;BR /&gt;This can easily be modiied to allow passing the number of iterations and the number of seconds to sleep, as:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset -i I=0&lt;BR /&gt;while (( I &amp;lt; $1 ))&lt;BR /&gt;do&lt;BR /&gt;  date&lt;BR /&gt;  let I=I+1&lt;BR /&gt;  sleep $2&lt;BR /&gt;done&lt;BR /&gt;#_end&lt;BR /&gt;&lt;BR /&gt;Thus, the command: ./my.sh 10 5&lt;BR /&gt;&lt;BR /&gt;...will loop 10-times, pausing 5-seconds each time.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Sat, 11 Aug 2001 15:04:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564426#M919435</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-08-11T15:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: Looping  a script  with sleep..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564427#M919436</link>
      <description>Hello Richard,&lt;BR /&gt;&lt;BR /&gt;well, how about "at" - if your account is permitted to use&lt;BR /&gt;it? Write a script, execute it it form"at" and make it&lt;BR /&gt;restart itself with "at" again a few minutes later...&lt;BR /&gt;&lt;BR /&gt;If that script goes  "crazy" it will not restart itself any&lt;BR /&gt;longer.&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;   Wodisch</description>
      <pubDate>Sat, 11 Aug 2001 15:07:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564427#M919436</guid>
      <dc:creator>Wodisch</dc:creator>
      <dc:date>2001-08-11T15:07:12Z</dc:date>
    </item>
    <item>
      <title>Re: Looping  a script  with sleep..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564428#M919437</link>
      <description>Hello&lt;BR /&gt;&lt;BR /&gt;Mr. James: would I run your script from cron or with the &amp;amp; ?&lt;BR /&gt;&lt;BR /&gt;Wodisch: I did a man on the at command. I am root so I am sure I can set that up. Can you tell me more about setting up that freature?&lt;BR /&gt;&lt;BR /&gt;If I run the script on a non stop loop. even though it is not doing much is there a chance that cpu will go up? Or is there any harm from doing it that way instead of from cron? And how valid is my bosses comment about scritps going crazy and making zombies and runaways?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Richard &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 11 Aug 2001 15:35:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564428#M919437</guid>
      <dc:creator>someone_4</dc:creator>
      <dc:date>2001-08-11T15:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: Looping  a script  with sleep..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564429#M919438</link>
      <description>Hi (again) Richard:&lt;BR /&gt;&lt;BR /&gt;You could run the script I proposed via 'cron" or as a background job. If you start it in the background, do so with 'nohup' to divorce it from your shell.&lt;BR /&gt;&lt;BR /&gt;When a process "sleeps" it is taken off the CPU run queue.  There is very, very little overhead for this.  In fact, if you are continually testing for a condition or an event to happen, then you WANT to impose a wait or a sleep.  The technique is perfectly valid.&lt;BR /&gt;&lt;BR /&gt;As regards the 'at' mechanism.  Wodisch's suggestion is a nice one.  Indeed, it is often used in situations where you cannot easily 'cron' because the 'crontab' syntax doesn't easily offer the schedule you want.  Consider a cron job that you want to run, say, every 13 days.&lt;BR /&gt;&lt;BR /&gt;To allow the 'at' command for a user, you must add the user to the /var/adm/cron/at.allow file.  The concept and the syntax is the same as for the /var/adm/cron/cron.allow file.  See the man pages for 'at' and 'cron'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sat, 11 Aug 2001 15:50:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564429#M919438</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-08-11T15:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: Looping  a script  with sleep..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564430#M919439</link>
      <description>Hi Richard,&lt;BR /&gt;&lt;BR /&gt;The usual reason that scripts 'go crazy' when run from cron (which is really the better way) is that typically the prior invocation of your cron script has not finished before the next is fired off. You could have exactly the same problem with a looping script with sleeps. I prefer to do this sort of thing from cron because then you don't have to worry about starting it on reboot or having to write an rc script to do it. The better approach to this problem is to put some logic in to create a lock file when your process starts, do your stuff, and remove the lock file. If the next invocation fired off by cron sees this lock file it, it exits and does nothing. A variation on this is to let the process write its PID in the lockfile and the next process also checks via ps if the prior process is still running. This is a good additional check if the process is critical. This construct covers the case where the prior process died without removing the lockfile.&lt;BR /&gt;&lt;BR /&gt;Clay</description>
      <pubDate>Sun, 12 Aug 2001 15:09:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564430#M919439</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-08-12T15:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: Looping  a script  with sleep..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564431#M919440</link>
      <description>Hey mr clay &lt;BR /&gt;that sounds like some really good stuff.&lt;BR /&gt;If you dont mind taking the time.&lt;BR /&gt;How would I go about doing that?&lt;BR /&gt;&lt;BR /&gt;Richard</description>
      <pubDate>Mon, 13 Aug 2001 15:52:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564431#M919440</guid>
      <dc:creator>someone_4</dc:creator>
      <dc:date>2001-08-13T15:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Looping  a script  with sleep..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564432#M919441</link>
      <description>One more question.&lt;BR /&gt;All the options that were giving to me on this post work great.&lt;BR /&gt;But what is the difference from doing as Mr. James said with the typeset option or doing what Mr. Bezawada recommended. Or is it just personal perference. &lt;BR /&gt;&lt;BR /&gt;Richard&lt;BR /&gt;</description>
      <pubDate>Mon, 13 Aug 2001 15:57:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564432#M919441</guid>
      <dc:creator>someone_4</dc:creator>
      <dc:date>2001-08-13T15:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: Looping  a script  with sleep..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564433#M919442</link>
      <description>Hi Richard:&lt;BR /&gt;&lt;BR /&gt;'typeset' in the case I used for you, declares an integer variable.  This allows the expression to be tested syntatically correctly.&lt;BR /&gt;&lt;BR /&gt;The shell allows (in fact, creates) variables as they are encountered.  This is obviously not true in many languages.&lt;BR /&gt;&lt;BR /&gt;Using 'typeset' allows me to predeclare them; to establish them as integers to make arithmetic faster; mark them as readonly; cause data that is stored in them to be automatically converted from upper-to-lower case; etc.&lt;BR /&gt;&lt;BR /&gt;Perhaps the most powerful use of 'typeset' is to declare variables as "local" to a function or procedure.  In this way, the variable only exists (or its value only exists) within the scope of the function or procedure.&lt;BR /&gt;&lt;BR /&gt;Take a look at the man pages for 'sh-posix' and look at 'typeset' there.  &lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 13 Aug 2001 16:08:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564433#M919442</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-08-13T16:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: Looping  a script  with sleep..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564434#M919443</link>
      <description>Here you go Richard,&lt;BR /&gt;&lt;BR /&gt;This is an example of a script whicj uses a lock file to store the PID. The next time it is run, if the lock file is found it then reads the file to get the previous pid and does a ps to look for that process. If the process is found, the old one is still running and this invocation simply exits.&lt;BR /&gt;&lt;BR /&gt;Clay</description>
      <pubDate>Mon, 13 Aug 2001 16:52:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564434#M919443</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2001-08-13T16:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Looping  a script  with sleep..</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564435#M919444</link>
      <description>Hi Richard,&lt;BR /&gt;&lt;BR /&gt;if you want to run your script ( example : doMyJob.sh ) with a different sleeping time ( expressed in seconds ) each time you execute it ( after stopping it of course ) :&lt;BR /&gt;&lt;BR /&gt;while true&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;Commands ....&lt;BR /&gt;&lt;BR /&gt;sleep $1&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;#doMyJob.sh 10&lt;BR /&gt;#doMyJob.sh 20&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Magdi&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Aug 2001 09:50:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/looping-a-script-with-sleep/m-p/2564435#M919444</guid>
      <dc:creator>Magdi KAMAL</dc:creator>
      <dc:date>2001-08-14T09:50:37Z</dc:date>
    </item>
  </channel>
</rss>

