Automatically log on to multiple remote hosts to check whether the process is normal

Source: Internet
Author: User
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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.