Operating System - HP-UX
1753481 Members
4645 Online
108794 Solutions
New Discussion

Re: Append date with time to stdout

 
SOLVED
Go to solution
Alok_Behria
Advisor

Append date with time to standered output

Hi All,

 

I am using following shell script to verify database  run , also , I need to create a logfile , everytime it is kicked-off . we do use control-m to kick off jobs. The problem , I have , when I run this, the script will only add "success" to logfile, what i need to do is also add timestamp before the success. please advise on this.

#!/usr/bin/sh
. qa02
SID=ptmtrain
export DATE=$(date +m%d)
LOG_DIR=/home/oraadmin/test/dev_monitoring/logs
LOG_FILE=${LOG_DIR}/${DATE}.log
typeset -i mHHMM=`date +%H%M`
typeset -i mDD=$(date +%d)
mDay=`date +%a`
echo "select 'success' from dual;" | sqlplus -s oramonitoring/temp123@$SID | grep success  >> $LOG_FILE
if [[ $? -ne 0 ]]; then
echo "$SID is down, pleae look into this" | mailx -s "$SID has issue , please look into this" aajitkumar@csc.com
fi
else
:
fi

 

2 REPLIES 2
Patrick Wallek
Honored Contributor
Solution

Re: Append date with time to standered output

The easiest way is to add the following right before your 'echo "selcect...."' statement.

 

echo ${mDay} >> $LOG_FILE

Dennis Handly
Acclaimed Contributor

Re: Append date with time to stdout

If you want the date in your file, just put it there:

date >> $LOG_FILE

 

>echo ${mDay} >> ...

 

This only has the day of the week.