[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 482
  • Last Modified:

This is in AIX 5.3..I need a script that needs to run a command every 0.5 seconds

This is in AIX 6.1.and REHL 4.I need a script that needs to run a command every 0.5 secs..Please let me know as how this can be done
0
aixtutorial
Asked:
aixtutorial
1 Solution
 
omarfaridCommented:
how long does it take the command to finish? if it is more that 0.5 sec then what is the use?

sleep will give you to wait minimum 1 sec then resume
0
 
wesly_chenCommented:
GNU sleep supports arbitrary floating point numbers (using a period before any fractional digits)


while  true 
do
  <command>
  sleep 0.5
done

Open in new window

0
 
Murugesan NagarajanSubject-matter expert at delivery, implementation, and automation at UNIX oriented operating systems (Windows: CYGWIN_NT MINGW32_NT MINGW64_NT)Commented:
As informed by omarfarid
          >  sleep will give you to wait minimum 1 sec then resume


You can use the following:
cat sleep_halfSec.c
#include <unistd.h>
#include <time.h>
/* Sleep for milliseconds */
void sleepMilli(int millisec)
{
        struct timespec tmsp;
        tmsp.tv_sec = millisec / 1000;
        tmsp.tv_nsec = (millisec % 1000) * 1000;
        nanosleep(&tmsp, NULL);
}
int main()
{
        sleepMilli( 500) ; /* which is 1000*0.5 */
        return 0 ;
}

Open in new window



Compile that code
cc -g  sleep_halfSec.c -o sleep_halfSec

Open in new window



Here goes the script which you need:

cat sleep_halfSec.sh
#!/bin/ksh
while true
do
        echo Execute your required command
        echo sleep for 0.5 second
        sleep_halfSec
        echo Execute your required command
done

Open in new window

or
cat sleep_halfSec.sh
#!/bin/ksh
while [ 1 ]
do
        echo Execute your required command
        echo sleep for 0.5 second
        sleep_halfSec
        echo Execute your required commands
done

Open in new window

0
 
woolmilkporcCommented:
Adding to wesley_chen's suggestion:

GNU sleep is in coreutils, from here:

http://www.perzl.org/aix/index.php?n=Main.Coreutils
with this prerequisite:
http://www.perzl.org/aix/index.php?n=Main.Gmp

Install with

rpm -i --nodeps gmp-5.0.2-1.aix5.1.ppc.rpm
rpm -i --nodeps coreutils-8.14-1.aix5.1.ppc.rpm

and call GNU sleep with

/opt/freeware/bin/sleep 0.5

0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now