How to start a command for example ls -la
every 5 seconds on Solaris ? . I'm searching for something like watch -n 5 ls -la
3 Answers 3
You can make a script using sleep
, as described in this ticket
Basically, this make something like that:
while true
do
ls -la
sleep 5
done
You can launch this in a screen if you want to reach it at any moment, or you can redirect the output in a file that you can consult at any time (because i think screen
, as watch
, isn't installed with the basic solaris installation).
Building on both answers by @Carpette and @AmitSanghvi:
Loops of the form
while true
do
...
sleep 5
done
can be notoriously difficult to interrupt with Ctrl+C. On the other hand, the sleep
interval is a prime target for keyboard interruption.
Better is:
while sleep 5
do
...
done
To build on the earlier answer by @Carpette ... here's a parameterised version of the same script.
if [ $# -ne 2 ]; then
echo "ERROR: Syntax is script <command> interval"
exit
fi
while true
do
eval "${1}"
echo "
++++++++++++++++++++++++++++++++++++
"
sleep 2ドル
done
Example usage:
~/scripts/watch.sh "tail -10 /oracle/home/alert.log" 5
watch
?