Contacting the sysadmin from command line
If you are a sysadmin, communicating with your users is an important aspect of your job. Phone, e-mail, SMS, and various service request systems are commonly used by most businesses. The problem with all these tools is that they require time and a certain degree of effort.
It is definitely important for a sysadmin to separate himself from the users with some bureaucracy: otherwise no work is going to be done, with all time being spent on the phone or reading e-mails. However, in any environment there is a particular class of users – application focals, network admins, database administrators – who can help the sysadmin to detect and troubleshoot a problem early before is becomes a major outage.
The following Korn shell script allows select users to contact you simply by typing your name and a brief message at the command line of a Unix server or workstation. This script has been written for Solaris but it can be easily modified for any other Unix operating environment.
#!/bin/ksh
# 2006-09-28
# krazyworks.com
TEXT=$(echo $*)
#---------------------------------------------------------------
# FUNCTIONS
#---------------------------------------------------------------
log() {
LOG="$HOME/igor.log"
TMP="/tmp/igor_log.tmp"
LINELIM=1000 ; LINEBUF=50 ; (( LINEMAX = LINELIM + LINEBUF ))
if [ ! -r "$LOG" ]
then
touch "$LOG"
fi
if [ -f "$LOG" ] && [ `wc -l "$LOG" | awk '{print $1}'` -gt $LINEMAX ]
then
cat "$LOG" | tail -$LINELIM > "$TMP"
mv "$TMP" "$LOG"
fi
chmod 777 "$LOG"
}
#---------------------------------------------------------------
message() {
if [ ! $TAIL ]
then
TAIL=1
else
(( TAIL = TAIL + 1 ))
fi
echo "`hostname` `date +'%Y-%m-%d %T'` $MSG" >> "$LOG"
tail -1 "$LOG"
}
#---------------------------------------------------------------
configure() {
USER=$(id | awk -F'(' '{print $2}' | awk -F')' '{print $1}')
HOST=$(hostname)
FROM="${USER}@${HOST}"
DEST="your_email@host.domain your_pager@host.domain"
SUBJ="Message from $USER on $HOST"
MAIL="/bin/mailx"
USERS="root oracle user1 user2 user3"
if [ ! -x $MAIL ]
then
MSG=$(echo "Error: $MAIL executable not found!") ; message
exit 1
fi
}
#---------------------------------------------------------------
send() {
if [ `echo $USERS | grep -c $USER` -gt 0 ]
then
echo "$TEXT" | $MAIL -r "$FROM" -s "$SUBJ" "$DEST"
else
MSG=$(echo "Error: User $USER is not allowed to run this script!") ; message
exit 1
fi
}
#---------------------------------------------------------------
confirm() {
MSG=$(echo "Your message saying - $TEXT - has been sent.") ; message
}
#---------------------------------------------------------------
# RUNTIME
#---------------------------------------------------------------
case `uname -s -r` in
# --- SunOS --------------------------------
"SunOS 5.6") log
configure
send
confirm ;;
# ----------------------------------
"SunOS 5.7") log
configure
send
confirm ;;
# ----------------------------------
"SunOS 5.8") log
configure
send
confirm ;;
# ----------------------------------
"SunOS 5.9") log
configure
send
confirm ;;
# ----------------------------------
"SunOS 5.10") log
configure
send
confirm ;;
# ----------------------------------
"SunOS 5.11") log
configure
send
confirm ;;
# ----------------------------------
*) echo "`uname -s -r` is not supported by this script. Exiting..."
exit 1 ;;
esac
Save this script as your name in a common executable directory like /usr/sbin. For example: /usr/sbin/Mike. Set file ownership to allow users to execute the file. You can use additional group ownership settings to further restrict access.
All a user would need to do to get your attention is to type something like:
> Mike please run the root.sh script so I can complete Oracle installation

