1833883 Members
1860 Online
110063 Solutions
New Discussion

Re: Scripting

 
AKAT
Advisor

Scripting

I have been given the task to write scripts to get BDF, yesterdays syslog ( critical erros) and any users who are logged in since yesterday.
I am new to scripting so will need help with my scripting.
Below is what I tried and works OK but this is not a clever script and the problem is it is OK if I run this script Tuesday to Friday ( as I will get the logs from the previous working day) but on Mondays I will need logs from Friday, Saturday and Sunday.
Can someone help me to write better script then the one below
I also need to email this report everyday

#!/bin/sh

yesterday=`TZ=GMT+23 date | cut -d " " -f 2,3`
HOSTNAME=`uname -n`

echo "This is $HOSTNAME server"
echo "========================"
echo
echo "bdf output of $HOSTNAME"
bdf
echo
echo "Syslog for $HOSTNAME"
echo "========================="
cat /var/adm/syslog/syslog.log | grep "$yesterday" | grep -i -E 'crit|warn|ems|full'

echo "Database errlog for $HOSTNAME"
echo "========================="
cat /uv/errlog | grep "$yesterday"

# Ensure that yesterday's users killed by IT Operations"

echo "Yesterday's users who are still logged in on $HOSTNAME"
echo "======================================="
last | grep "$yesterday" | sort -n -k 8

# Overnight Printing
echo
echo "Overnight Printing Status for $HOSTNAME"
echo "================================="
lpstat -o

#mailx -s "Report" ask@test.com < /home/ask/report.log
3 REPLIES 3
Manuela Italia
Advisor

Re: Scripting

Hi

If I understand correctly, you need every day an email report of the previous day.
If your script is ok, you just have what you want:
you can schedule your script with crontab, like that:
00 08 * * * /your/script
and on Monday morning you will find on your mailbox 3 different email for Friday, Saturday and Sunday report.

if you want to change the way to obtain "yesterday" date, i suggest you this script:
http://www.securebrain.com/ydate.html
that makes you free from hours limitation.

Is it enough? or you prefere to change the script?


manu

Hein van den Heuvel
Honored Contributor

Re: Scripting

Welcome to the forum!

Kindly change your name to something meaningfull, or sign with a name, even if just pretent, such that we do not have say 'hey you'.

>> I am new to scripting so will need help with my scripting.

1) everything has been done before.
Use that, at least as a starting point.

2) search for examples which might be close.
If you'd like to look here for older answer first try:
try google: +site:itrc.hp.com +hpux +yesterday +syslog

and google for 'caljd'.

ditto for df/bdf

3) Read, try, read some more, try some more.

Regards,
Hein van den Heuvel
spex
Honored Contributor

Re: Scripting

Hello,

I like Manuela's suggestion to simply schedule the script to run every day, and then simply read a few messages on Monday. But if you have your heart set on aggregating logs over the weekend, you will have to perform date calculations in your script. A. Clay Stephenson has written a script for just such a purpose, which I have attached to this post.

A few stylistic comments on your script:

1) Instead of printing to stdout via 'echo ...', redirect output to a file that you keep appending. Then take this file as stdin to the 'mailx' command.

2) The POSIX-mandated form of command substitution is $() over ``.

3) Do not use 'cat' to pass the contents of a file through a command pipeline when you don't need to. Many of the standard UNIX commands, such as 'grep', take an input filename as an argument. So, for example, instead of 'cat file | grep foo' do 'grep foo file'.

4) The preferred path to the POSIX shell is '/usr/bin/sh'. Note that '/bin' is a symlink to '/usr/bin' and its use is deprecated.

Here is an excellent guide to shells under HP-UX:

http://docs.hp.com/en/B2355-90046/

PCS