Original article: http://blog.chinaunix.net/u/12442/showart_391130.html
In many cases, the administrator needs to log on to multiple hosts and check whether the process is running properly.
The following script is successfully implemented in the HP-UX, it is estimated that there is no problem in other platforms, after all, it is Bash, huh
1. The prerequisite for script implementation is that the/. rhosts of all the remote hosts contain the name of your current local host.
2. Create a host list
3. Redirect the output to the log file: Date of the current day. Ping. Log
4. Use tail-F to view Real-time running results.
#! /Sbin/SH Logfile =/etc/chk/log/'date + % Y % m % d'. Run. Log If [-F "$ logfile"]; then Rm $ logfile Fi Touch $ logfile Tail-F $ logfile & For I in 'cat/etc/chk/hosts. Run. lst' Do (Sleep 10; echo "PS-Ef | grep run | WC-L"; sleep 3; echo exit;) | rlogin $ I>/etc/chk/run. tmp Tail-N 3/etc/chk/run. tmp> $ logfile Done Rm/etc/chk/run. tmp Kill 'ps-f-u root | grep "tail-F $ logfile" | awk '{print $2} ''>/dev/null Exit |