2

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

asked Mar 3, 2016 at 13:18
3
  • 1
    and what's wrong with watch ? Commented Mar 3, 2016 at 13:25
  • @Carpette, I'm not sure it comes with a default Solaris installation; I see a 3rd-party package available at opencsw.org/packages/CSWwatch Commented Mar 3, 2016 at 13:27
  • FWIW OpenCSW is a pretty common repo for installing software on Solaris. I would just as a matter of best practice have it available unless you have a reason to leave it off (security clearance or some such). Commented Mar 3, 2016 at 13:40

3 Answers 3

6

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).

answered Mar 3, 2016 at 13:34
1

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
answered May 26, 2021 at 22:41
0

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
AdminBee
23.6k25 gold badges54 silver badges77 bronze badges
answered May 26, 2021 at 9:06

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.