#!/bin/ksh
#   17nov2004   john meister
#  purpose:  script to execute command on all servers - encapulate in quotes
#  must be run from designated master ssh server
#
#  used to manage over 70 systems as the sole systems administrator.  could gather information from
#   all systems with one command, summarized in an email, and also create a web page readable log file.
#
#    e.g.    sh ./runnow.sh "df -h | grep /dev/sda"       (would replace the "x" with the "df" command command for every host.)
#
USAGE="usage: sh ./runnow.sh , runs command on all systems - NOTE: encapsulate complex commands in quotes"
##################################
#       HEADER and FILE INFO
##################################
#
## CMD strips off special characters and paths in order to create a unique log file, FNAME
#
CMD="`echo "$1" | tr ' ' '_'  | tr '/' '-' | tr '|' '-' `" ; export CMD
DATE=`date | cut -c 5-11` ; export DATE
FDATE=`/usr/bin/date +%d%b%y-%H%M` ; export FDATE
FNAME="$CMD.$FDATE" ; export FNAME
#
## note that the logfile is placed in a web directory, the text file is also emailed to "jm".
#
LOG="/var/apache/htdocs/SystemInformation/$FNAME.txt" ; export LOG
echo " -- $CMD -- on $DATE -- "| tee $LOG     ###### NOTE writes over file when reexecuted ######
echo " ----------------------------------------------- "| tee -a $LOG
##############################################
# Solaris 9 and SuSE Linux systems use ssh
##############################################
HOSTS="host1 host2 host3 host4 ...
...host25 host26 host27" ; export HOSTS
#
for x in  $HOSTS
        do
	#
	## note that for each system in "HOSTS" basic system info is also provided 
	#
        echo "\n### $x (`ssh $x uname -r` on `ssh $x uname -i | awk -F, '{print $2}'`) ###" | tee -a $LOG
	#
	## this is the actual command being processed $x from the input and $1 is the host to run on 
	#
        ssh $x $1 | tee -a $LOG
        done
##################################
# Solaris 8 systems use rsh
##################################
HOSTS8="host28 host29 host30 host31...
...host49 host50 host51 host52" ;  export HOSTS8
#
for x in  $HOSTS8
        do
        echo "\n### $x (`rsh $x uname -r` on `rsh $x uname -i | awk -F, '{print $2}'`) ###" | tee -a $LOG
	#
	## there was a problem with SSH on Solaris 8, it used an earlier version that was incompatible, making it easier to use "rsh"
	## rsh is NOT recommended as it uses the Berkley "r" protocols that are insecure.  This was used on a private network.
	#
        rsh $x $1 | tee -a $LOG
        done
#
##################################
echo " ------------- " | tee -a $LOG
echo "webpage:  http://the_server.com/SystemInformation/$FNAME.txt" | tee -a $LOG
echo " ------------- " | tee -a $LOG
mailx -s " $1 (`date +%d%b%y`)" jm < $LOG
##################################
##  the following were variations of this script to get different information - saved below for notes...
#
#      ssh $x uptime | awk '{ print "system up " $3 " " $4 " at " $1 " load avg=" $10$11$12$13 }' | tee -a $LOG
#      ssh $x sar | grep Average | awk '{print "sar average is usr_"$2" sys_"$3" wio_"$4" idle_"$5"%"}' | tee -a $LOG
#      echo "System messages ($DATE):" | tee -a $LOG
#      ssh $x cat /var/adm/messages | grep "`date | cut -c 5-11`" | tee -a $LOG
#      rsh $x uptime | awk '{ print "system up " $3 " " $4 " at " $1 " load avg=" $10$11$12$13 }' | tee -a $LOG
#      rsh $x sar | grep Average | awk '{print "sar average is usr_"$2" sys_"$3" wio_"$4" idle_"$5"%"}' | tee -a $LOG
#      rsh $x cat /var/adm/messages | grep "`date | cut -c 5-11`" | tee -a $LOG
#
##################################


Simply Linux: Basics  Full Size Jeep Buyer's Guide Using BASH on Windows 10
Practical Suggestions for Microsoft Windows
Linux Tackles Microsoft
12 hour Video Course by john:
The Art of Linux System Administration
published by O'Reilly Media
Study Guide for the LPIC-2 Certification Exams
search for:
on the internet, or:
JohnMeister.com-fotos
LinuxMeister-Linux
BibleTech- Bible overview

overview of mankind's history
Biblical history:
"Promises and Prophets"

Wagoneers

FULL SIZE JEEPS

JeepMeister
"Jeep is America's
only real sports car."
-Enzo Ferrari


MeisterTech
Diesels +

One Page Overview of Linux Commands

click for an image of the 5 essential Linux commands

An Intro to Linux
AMSOIL product guide,
or, AMSOIL web, or 1-800-956-5695,
use customer #283461

Amsoil dealer since 1983
purchase AMSOIL
at Midway Auto on SR9 in Snohomish,
or at Northland Diesel in Bellingham, WA


SJ - 1962-1991

XJ - 1984-2001

WJ - 1999-2004

KJ - 2002-2007

WK - 2005-2010

Find the recommended
AMSOIL synthetics
for your Jeep

CJ-10A - 1984-1986

Jeepsters

MJ - 1984-1992

Willys - 1946-1965

Other Jeeps (FC)