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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script help! 1

Status
Not open for further replies.

Larshg

Programmer
Mar 1, 2001
187
DK
I need to modify this script.

Right now it ONE checks log files for how the job ended, I need it to check a range of logfiles 15 to 20 and I need it to take the logfiles that are created AFTER 10 am. today.

I know the way the log files that I need to check looks
“NAME”_”jobreg-not importent”_”SND”_”DATE-YYYYMMDD”_”TIME-HHMMSS”.log

I know the “NAME”, “jobreg” and “SND” of alle the logfiles(they are the same every day)
Here are some examples of the logfiles that I want to look at notice that the only time that differs in the files are the date.

BLPREP_10N01022001_SND_”date after today at 10 am.”
ARPHPPRCVRY_BYREQ_SND_”date after today at 10 am.”
ARPHPRSPL_ARPAY_DDB_SND_”date after today at 10 am.”
ARPHPRCHK_ARPAY_DDB_SND_”date after today at 10 am.”
ARPB01DAYREP_ENDDAY_SND_”date after today at 10 am.”


more larstjeklog.sh
#!/bin/ksh
found=``
status=``
echo $status

# Check number of parameters
if [ $# != 1 ]
then
echo SYNTAX : Insert logfile as parameter
echo EXAMPLE : tjeklog.sh BLPREP_10N01022001_SND_20010204_070223.log
return 1
fi
print ""
while [ "$found" = "" ]
do
logfile=`ls /usr/users/operator/var/snd/log/$1`
status=`tail -10 ${logfile} | grep "Operational Job ended" `
#status=`tail -1 ${logfile} | grep "0" `
echo $status
if [ "$status" != "" ]
then
found=1
echo "$status" |mailx -s Status test@hotmail.com
else
echo "Jobs still running"
fi
sleep 100
done
exit;
 
Hi

I've tryede useing your awk, but now I am only getting the date as an output. here are the 2 lines in my script

SMS_MESSAGE=`echo $MESSAGE|awk -F"log/" '{print $NF}'|awk -F"|awk -F"_SND" '{print $1}'`
echo "$DATE $SMS_MESSAGE"|$MAIL EOD_job_fail 72126924@note.sonofon.dk
echo "SMS the operator"

And here is the out the SMS text
Wed Mar 6 19:50:45 MET 2002


Thanks
Lars
 
The test below worked for me.
Maybe you need to check the value for $MESSAGE
If $ MESSAGE is something other than the line you gave
me, the awk statement may not work.
just add echo "MESSAGE = $MESSAGE" to test the script.

export MESSAGE="Wed Mar 6 13:35:19 MET 2002 Operational Job ended with failure FOUND in /usr/users/operator/var/snd/log/DMDISP_ENDDAYERR_SND_20020304_154514.log"

# echo $MESSAGE
Wed Mar 6 13:35:19 MET 2002 Operational Job ended with failure FOUND in /usr/users/operator/var/snd/log/DMDISP_ENDDAYERR_SND_20020304_154514.log

# echo $MESSAGE|awk -F"/" '{print $NF}'
DMDISP_ENDDAYERR_SND_20020304_154514.log

# echo $MESSAGE|awk -F"/" '{print $NF}'|awk -F "_SND" '{print $1}'
DMDISP_ENDDAYERR

Robert Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
 
I seem to be awk'ing everything away. here is the awk line and the output

echo $MESSAGE > message
SMS_MESSAGE=`echo $MESSAGE|awk -F"log/" '{print $NF}'|awk -F"|awk -F"_SND" '{print $1}'`
echo $SMS_MESSAGE > sms_message

The message contains something like this:
Operational Job ended with failure FOUND in /usr/users/operator/var/snd/log/MPSDUMMYFAIL_ENDDAY_SND_20020305_235744.log

The sms_message is empty - all it has is an empty line!

/Lars
 
Your awk statement looks fine to me.
I bet there is a problem with the input
you are piping to awk.

I see you have the line echo $MESSAGE > message
What's in the message file?

Robert Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
 
The message file contains something like this:

Operational Job ended with failure FOUND in /usr/users/operator/var/snd/log/MPSDUMMYFAIL_ENDDAY_SND_20020305_235744.log


The sms_message file is empty - all it has is an empty line!



 
vi the message file. Is it one line that wraps around or two?

If it's two, then that's why the awk won't work.

try this:
SMS_MESSAGE=`echo $MESSAGE|grep "/log"|awk -F"log/" '{print $NF}'|awk -F"|awk -F"_SND" '{print $1}'`

the exta grep statement will remove any extra unwanted lines
before piping to awk (grep "/log")

Robert



Robert Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
 
Its only one line

I triede splitting the awk up to check - like this
echo $MESSAGE > message
SMS_MESSAGE=`echo $MESSAGE|awk -F"|awk -F"_SND" '{print $1}'`
echo $SMS_MESSAGE > sms_message

but the sms_message still just contains an empty line

/Lars
 
I've triede somethin else

echo $MESSAGE > message
SMS_MESSAGE=`echo $MESSAGE|awk '{split($1,res,"_SND"); print res[1]}'
echo $SMS_MESSAGE > sms_message

In this case the sms_message contain
the word:
Operational

I thought it would give me evrythin before _SND - but it doesn't


/Lars
 
Also add the statements
echo $MESSAGE
echo $MESSAGE|wc -l

so you can see on the screen
what the value of $MESSAGE is
followed by a line count.

Try this from the command line on your system.
If you see the correct output on your screen,
there is something wrong with the $MESSAGE variable
before it is piped to awk.

export MESSAGE="Wed Mar 6 13:35:19 MET 2002 Operational Job ended with failure FOUND in /usr/users/operator/var/snd/log/DMDISP_ENDDAYERR_SND_20020304_154514.log"

# echo $MESSAGE
Wed Mar 6 13:35:19 MET 2002 Operational Job ended with failure FOUND in /usr/users/operator/var/snd/log/DMDISP_ENDDAYERR_SND_20020304_154514.log

# echo $MESSAGE|awk -F"/" '{print $NF}'
DMDISP_ENDDAYERR_SND_20020304_154514.log

# echo $MESSAGE|awk -F"/" '{print $NF}'|awk -F "_SND" '{print $1}'
DMDISP_ENDDAYERR Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
 
Ha Ha - I've found the problem - a stupid thing - check out the difference between the to lines the first one works and the second one is the old one

SMS_MESSAGE=`echo $MESSAGE|awk -F"/" '{print $NF}'|awk -F "_SND" '{print $1}'

SMS_MESSAGE=`echo $MESSAGE|awk -F"/" '{print $NF}'|awk -F"|awk -F"_SND" '{print $1}'`



Thanks for all your help - I don't think there are any more problems

A well deservede star


Regards
Lars Grynderup
lsg@sonofon.dk
 
One last thing now I can't make it work when I place it in another file ex. the naming filter

NAME_FILTER=`cat [/usr/users/operator/runj/itdrift/LSG/FILTER]|head -1`

When I execute my script it just says :
cat: cannot open [/usr/users/operator/runj/itdrift/LSG/FILTER]

/Lars

 
Lars, you don't need the square brackets. When you see them in an example people usually mean "put your filename in here" Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top