Unix - Optimize your work - Tips for Production Support


Make use of .profile file. If there is not one , create one within home directory.

a. Add aliasis for common Unix commands.
a.1 shortcut to move to logs directory
logs = 'cd /dfsd/sdfsd/fsdf/sdf/logs'

a.2 shortcut to show errors in running logs.
tlogs = 'tail -f /dfsd/sdfsd/fsdf/sdf/logs/xyx.logs | grep "ERROR"'

b. Change the landing directory, make it to your application log directory
cd /dfsd/sdfsd/fsdf/sdf/logs

Use ! and !! to execute last commands. As an alternative to the exclamation mark commands, you can use the up/down arrows to move back and forth in the command history and repeat/edit a command.


Use the combination of Grep , Find , Tail , Cat to play with the log file.


3.a To see error/xception lines in running logs
tail -f xyz.log | grep "ERROR"
tail -f xyz.log | egrep "ERROR|xception"

3.b To see only lines containing an error / exception in last 5000 lines.

tail -5000 /opt/WebSphere/AppServer/profiles/application/logs/SystemOut.log | grep -i "FileNotFoundException"

3.c To see lines containing any of the multiple errors / exceptions in running logs

tail -f /opt/WebSphere/AppServer/profiles/application/logs/SystemOut.log | egrep "(WSWS3713E|WSWS3734W|WSVR0605W|javax.net.ssl.SSLHandshakeException|ThreadMonitor)"

3.d To see Error Snipets in running logs.

tail -f /opt/WebSphere/AppServer/profiles/application/logs/SystemOut.log | sed -n '/ERROR/,/EST/p'

3.e To get all error / exception snippets in another file.

sed -n '/ERROR/,/EST/p' /opt/WebSphere/AppServer/profiles/application/logs/SystemOut.log* >> newFile.txt

3.f To find occurences of a particular error in last n days.

find /opt/WebSphere/AppServer/profiles/application/logs/ -iname "SystemOut*" -mtime -7 -exec zgrep "FileNotFoundException" {} \; >> logAnalysis.txt

3.g To count number of error / exception occurences in a log file.

sed -n '/ERROR/,/EST/p' /opt/WebSphere/AppServer/profiles/application/logs/SystemOut.log | grep "LogicBlockSetupException" | wc -l

3.h To report the file size of all files bigger than 2 mb and older than 30 days.

find . -type f -size +4096 -atime +30 -exec \du -sk '{}' \;

Create shell script for the system monitoring task.


Create shell script for log monitoring task.


Use Scripts to continuously monitor the state(up/down) of application.

To Send an email if the website is down for maintanance

while true ; do
curl websiteaddress.com | grep -q "Down for Maintenance"
if [ $? -eq 0 ] ; then
echo "Website is Down" | mail -s "Website is down for maintenance" email@address.com
; fi
sleep 20

To Send an email if the website is down and doesn’t contain “Normal String”.

while true ; do
/usr/bin/wget "www.example.com" --timeout 30 -O - 2>/dev/null | grep "Normal operation string" || echo "The site is down" | /usr/bin/mail -v -s "Site is down" your@e-mail.address
sleep 20

Related Posts -

Unix Shell Scripts for Log Monitoring , Production and Application Support.