running commands to remote host from centralized host

Gurus/Experts

We have a centralized UNIX/Solaris server from where we can actually ssh to all other UNIX/Solaris servers...I need to write a script that reside on this centerlized server and do FileSystem monitoring (basically run df -h or -k) of other remote servers and then send an email to me something like below (just an example)......we have got plenty of these server running many databases

Server A

/oracle/DATABASE_A/archivelog/ 90% full

Server B

/oracle/DATABASE_B/archivelog/ 20% full

Could anyone please help?

Create a file that has all of your hosts listed within it:

servername1
servername2
servername3
etc.c.

Then, on the central host:

for host in `cat /path/to/hostlist`; do echo $host; echo "========"; ssh $host df -h | awk '{print $1"\t"$5}'; echo; done >> output_file 

I'm sure that there's an awk command to skip the first line, but it escapes me at the moment....

This promts for password, Is there any way to pass password to ssh,thru any file..?

Just search this site for "Public Key Authentication"

[quote=avronius;302344831]

for host in `cat /path/to/hostlist`; do echo $host; echo "========"; ssh $host df -h | awk '{print $1"\t"$5}'; echo; done >> output_file [/code
Too fast, you forgot the quote's for remote command ... and try to win the UUOC award in the same time :rolleyes:
while read H; do ssh $H "df -h" | awk 'BEGIN{printf "%s\n%s\n","'"$H"'","========"}NR>1{printf "%s\t%s\n",$1,$5}END{printf "\n"}';done < /path/to/hostlist > output_file

Hmmm - I was under the impression that the piped awk takes place on the host that the script is running on - not the remote host - does it not?

---------- Post updated at 06:34 AM ---------- Previous update was at 06:31 AM ----------

One day this site will break me of my reliance on cat, but apparently it wasn't yesterday :slight_smile:

Thanks...few things to clear; we do need password to connect to remote hosts from this centralized server.....

I have changed things a bit; I have managed to ssh <sever1> and run the script located on the remote server (i.e. server1); but output of the script is needed to send back to the centralized server; the script is below that I am planing to run on each server.....

how can I send output of below script back to centralized server in a file; and i need that file mailed to me?

--Script to connect to remote servers from centeralized host
while read H; do ssh $H /ora/rman/scripts/bk1.sh 'BEGIN{printf "%s\n%s\n","'"$H"'","========"}NR>1{printf "%s\t%s\n",$1,$5}END{printf "\n"}';done < /export/h
ome/oracle/servers.lst > out.txt

File servers.lst contains

server1
server2

But I think its only working for server1

--The script will go to the archivelog directory and check for successful and failed archivelog backups (each server hosts many databases)

chkbck ()
{
for i in `ls /ora/rman/logs/`;
do
find /ora/rman/logs/$i/backup_a*.log -mtime -1 2>/dev/null
done
}

for i in `chkbck`;
do
print $i | cut -d"_" -f3
print $i
grep Exit $i

if egrep -i 'exit status 1' $i
then
print $i
fi

done