From time to time, you want to run a simple command on hundreds of servers, such as `ps -ef|grep abcd' to see if a process named abcd is running on them. Without manually logging into each of them, how do you do it? My scripts automate the whole process that would otherwise be extremely tedious. #!/bin/bash #ck_host.sh: Runs a command on remote hosts automatically (unless preceded by #) #Please change the two arguments for ck_host.exp only (for host and account password). #The actual command to run is changed in a separat script, ck_host.exp. #WARNING: Make sure this file is only readable by this user: chmod 700 ck_host.sh ./ck_host.exp server1 password1 | sed '/^spawn/,/assword: /d' ./ck_host.exp server2 password2 | sed '/^spawn/,/assword: /d' ./ck_host.exp server3 password3 | sed '/^spawn/,/assword: /d' ... (May need `yum install expect' first) #!/usr/bin/expect #ck_host.exp: This Expect script takes two arguments, host to connect to (through ssh) and the account password. #It connects to the host and runs the command you specify below. Please limit the command to #read-only type, e.g. ls -l somefile, cat /etc/redhat-release, /usr/sbin/ntpq -p, ps -ef etc. #Yong Huang, 2012-07 #Please change the command inside the braces; need full path unless cmd is in /usr/bin #Comment must be on its own line, or preceded by ;# (not just #) #set cmd {cat /etc/redhat-release} #set cmd {ps -ef|grep pmon|grep -v grep} ;#Check which instances are running set cmd {grep -v ^# /etc/oratab|grep -v ^$} ;#Check which DBs are installed #set cmd {df -m} #set cmd {who -b} ;#Check server bootup time #set cmd {/usr/sbin/ntpq -p} #How to use env var on remote host; this example checks which SID is on that host (default if multiple) #set cmd {. /home/oracle/.bash_profile; echo $ORACLE_SID} #Normally you don't need to change anything below set host [lindex $argv 0] set password [lindex $argv 1] puts "$host --------------------------------------------------" spawn /usr/bin/ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $host $cmd expect_before eof { exit 2 } ;#basic network connection fails expect -re "assword:" set timeout 2 ;#give more time for initial connection send "$password\r" interact