Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple shell script to log system status

Status
Not open for further replies.

p0000h

Technical User
Feb 16, 2003
6
GB
Sorry in advance for this but I am totally new to Unix scripting and would appreciate some help. Working mainly on Network routers and switches, I am having trouble putting together a little script to run periodically outputting the disk, cpu and memory usage of a unix host. The host is a Nokia firewall but it uses a cut down BSD derived unix OS.

I would appreciate if anyone can post how I would actually get something like this to run say with cron to have 3 or so commands eg.. /usr/bin/uptime, /usr/bin/vmstat 1 4, /bin/dk - k every minute and log to a local file or a syslog server.

I know I can send all logs to a syslog server no problems but to get thes 3 specific commands to run would allow me to troubleshoot a recurring problem on the host. The limitations of the job pervent me from using snmp.

Regards,

Greig (user: p0000h)
 
With your examples your already half way there...

Try this:

#!/usr/bin/ksh -p

# This script will gather server info.
# Setup Variables here. (Add more if needed)
LOG="LOG_DIR_HERE/LOG_FILE_NAME_HERE"

# Setup functions here. (Add more if needed)
MTIME() { # This captures the time using military std.
print "`/usr/bin/date \"+%T\"`"
}

# Start log file.
exec 1>> ${LOG} # Capture stdout
exec 2>> ${LOG} # Capture stderr

# Now run command for system info.
MTIME
/usr/bin/uptime

MTIME
/usr/bin/vmstat 1 4

MTIME
/bin/dk -k

#EOS


Next setup cron to run this script every minute.
 
Thank you very much for the reply, it will provide me with a starting point for trying to understand the mechanics of the script.

Regards,

Greig (user: p0000h)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top