Operating System - HP-UX
1822144 Members
3289 Online
109640 Solutions
New Discussion юеВ

command to repeat last entered command indefinitely

 
SOLVED
Go to solution
Kenneth_18
Frequent Advisor

command to repeat last entered command indefinitely

if my memory serves me right, there is a command which will automatically loop a command indefinitely until disrupted. What is this command?

Thanks in advance!

E.g, I enter "ls -l /mydirectory" to check if a file has been newly created. The command will continously loop the "ls -l /mydirectory" command that I issued.

13 REPLIES 13
Rainer von Bongartz
Honored Contributor

Re: command to repeat last entered command indefinitely

Dont't know any such option.

I would use a shell loop

while true
do
ls -l /directory
sleep1
done

Regards
Rainer

He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Simon Hargrave
Honored Contributor

Re: command to repeat last entered command indefinitely

while [ true ]; do
ls -l /mydirectory
sleep 5
done
Sanjay Kumar Suri
Honored Contributor

Re: command to repeat last entered command indefinitely

Another loop

until false
do
command
sleep 1
done

Use Crtl+C to abort this endless loop.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Kenneth_18
Frequent Advisor

Re: command to repeat last entered command indefinitely

I'm not looking into a script. I forgot but there is a specific command in linux that does this so I was thinking that maybe this command has an HP-UX equivalent.

Thanks anyway.
Stuart Browne
Honored Contributor

Re: command to repeat last entered command indefinitely

As a linux user for many years, I've never heard of such a thing. I'd be interested if you remembered what it is.

In truth however, I can't see any good reason for such a thing to exist.
One long-haired git at your service...
Sundar_7
Honored Contributor

Re: command to repeat last entered command indefinitely

I cannot tell you whether such a command exists or not in Linux but just curious, are you sure it is not some kind of an alias set up in your Linux box ?

I have never heard of such thing in HP-UX.
Learn What to do ,How to do and more importantly When to do ?
Kenneth_18
Frequent Advisor

Re: command to repeat last entered command indefinitely

After doing some search in the net, the linux command I'm referring to is the "watch" command. Well it's not an intrinsic command but a bprobably part of the distribution. I think I first encountered this command in RH9.
Stuart Browne
Honored Contributor

Re: command to repeat last entered command indefinitely

By the looks of it, you shouldn't have too many issues getting the soruce code for this and compiling it under HP-UX, as it's a very simple program.

In any case, some of the documentation distributed with Watch is as follows:

WATCH
A little program similar to another called 'vis' which simply re-displays in a polling fashion the output of other programs. "watch ps --sort:utime" might be dubbed a poor man's 'top'. Though this has been included in procps for some time it hasn't been built or installed by default. It is now.

All that being said, 'vis' on HP-UX does nothing like this.
One long-haired git at your service...
Sanjay Kumar Suri
Honored Contributor

Re: command to repeat last entered command indefinitely

Hello Kenneth

Make a small script on the lines of above posts say watch. Give it +x permission and put in /usr/local/bin.

until false
do
#echo $1
$1
sleep 1
done

So with this you can give commands such as:

watch ls
or
watch "ls -l"

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Kenneth_18
Frequent Advisor

Re: command to repeat last entered command indefinitely

I've created such a script already. My problem is executing compound and piped series of commands. The script I made won't work unles somebody can show me how. The simple script I made is like this:

myscript:

#!/bin/sh
while true
do
$1
done

when you do a $myscript "ps -ef|grep XXX", it doesn't give the correct output.
Sanjay Kumar Suri
Honored Contributor

Re: command to repeat last entered command indefinitely

It is tricky. Check this one (You can modify further as per your needs):

until false
do
case $# in
1)
$1
sleep 1
;;
2)
$1 | $2
sleep 1
;;
*) echo "Invalid..."
esac
done

Give the command as below (Don't use the pipe):
$myscript "ps -ef" "grep XXX"

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Olivier Decorse
Respected Contributor
Solution

Re: command to repeat last entered command indefinitely

The script that works is :

#!/bin/sh
while true
do
eval $1
done

Then, you have to use this syntax :
./myscript 'ps -ef | grep XXX'

Olivier.
They say "install windows 2k, xp or better", so i install unix !
Kenneth_18
Frequent Advisor

Re: command to repeat last entered command indefinitely

Thanks Olivier, it works!