############################################################################### # SMaRT (Simple Monitoring and Reporting Tool) - v1.0 for Slackware / Redhat # Written by ozlo [ozlo@plink.freeservers.com] on 07.22.2002 # # SMaRT is a tool that monitors which users are logged into the system, their # IP or hostname, terminal, login time, idle time, and will list up to 3 or 4 # processes they are running. It will refresh every 60 seconds by default, or # can be changed to update as often as necessary by changing the lines: # [time=`expr $time + 60`] AND [sleep 60] to the desired value. To exit the # script once it is running, simply hit CTRL-C. # # *NOTE* # If a user is logged in more than one time, the process list might not be # displayed correctly. Also, this script works best on smaller systems where # there are about 15 or fewer users logged in concurrently. And I decided to # not have root's processes displayed since there are usually so many and it # would be pointless to monitor that. # #!/bin/bash time=0 while [ -z $1 ] do clear echo echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" echo "%[USER]%%%[TTY]%%%%[IP/HOSTNAME]%%%%[LOGIN]%%[IDLE]%%[PROCESSES]%%%%%%%%%%%%%%%" echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" for usr in `users | sort | grep -v "root"` do echo -e " \c" echo -e "`w -h $usr | cut -c1-50` \c" echo -e `ps -U $usr | grep -v "TIME CMD" | cut -c24-53 | paste -s - | cut -c1-30` done echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" time=`expr $time + 60` minutes=`expr $time / 60` seconds=`expr $time % 60` echo -e "Total users online:`who | wc -l`\t\t\t `date`" echo -e "Time spent monitoring: $minutes minute(s) $seconds second(s)" trap "echo -e '\n\tSMaRT v1.0\n\t[ozlo@plink.freeservers.com]\n'; exit" 2 15 sleep 60 done