user input date

I am trying write a script that takes user input date in the format "Mar 18". If it is march1 it is like "Mar 1" . Once i take this input i will go back to my log files and search for any failed transactions recorded that day. If there are then i will send it to a file and mail it.

I am struggling with date part, rest of the script is ready. I tried this for current date, but enhancement is to take user input.

Thanks,
Gundu

why are you focalizing on date format?

you may ask to the user to enter the date like this 20050301 as argument of the command ex:

your_script 20050301

after you can manage the date argument to transform it to match the expression you're grepping in the log files

OK I can input like 2005-03-18, i need help comparing this string with date in log file. How can i do that.

Gundu

try with strptime() function :wink:

I don't find samples to know how to use it...

I guess you should be able to do something like this:

my_var=strptime("my_string","date format",tm)

I didn't understood what "tm" stands for :-/

What does the date look like in the logfile?

my log file has date format : 2005-03-18

if it is ok to input the date in that format then this should work for sh, ksh or bash
I have written assuming ksh

#!/bin/ksh
LOGFILE="/log/files/error"   # update this to the path of your logfile
EMAIL="someone@somewhere.com"  # update this to your email address


grep ${1} $LOGFILE | uuencode transactions.txt | mailx -s "Matched Transactions for date ${1}" ${EMAIL}

Without knowing what a failed transaction looks like I can't suggest how you would filter out any other information.

I think I confused you. When I do this inmy script:

echo "Date: \c"
read xxx

I am expecting a date input, i will take that and look in all my audit log files, and search for that date and search for a failed transaction, if they exist i will e-mail else exit. My log entry is like :

2005-02-10 16:56:55 SYCCSSSS006010I1 46626 Provisioning Transaction Succeeded

Gundu

ok that makes things clears, though I assume if that a failure would look like:
2005-02-10 16:56:55 SYCCSSSS006010I1 46626 Provisioning Transaction Failed
if not update the bold part below.

# one email per logfile
#
# Assumes you have an array of log file names called FILES
#
echo "Date [YYYY-MM-DD] : \c"
read xxx

for file in ${FILES}; do
    grep "${xxx}.*Failed" ${file} > /dev/null 2>&1 || grep "${xxx}.*Failed" ${file} | uuencode ${file}_failedtransactions.txt | mailx -s "Failed Transactions for date ${xxx}" ${EMAIL}
done

# one email
#
# Assumes you have an array of log file names called FILES
#
echo "Date [YYYY-MM-DD] : \c"
read xxx

grep "${xxx}.*Failed" ${FILES} > /dev/null 2>&1 || grep "${xxx}.*Failed" ${FILES} | uuencode failedtransactions.txt | mailx -s "Failed Transactions for date ${xxx}" ${EMAIL}
done

Thanks, but how can i do if i don't have an array:

echo "Date:[YYYY-MM-D] : \c"
read xxx

cd $HOME/audit
ls -ltr //list all the audit log files
cat * > file2 /opens all the audit log files and saves it in file2

I need to use the input date from above and check in this file is the date matched and also the key word like success or failed is there, if it is there then e-mail me else exit.

Thanks,
Gundu

# one email per logfile
#
#
echo "Date [YYYY-MM-DD] : \c"
read xxx

for file in $HOME/audit/* ; do
    grep "${xxx}.*Failed" ${file} > /dev/null 2>&1 || grep "${xxx}.*Failed" ${file} | uuencode ${file}_failedtransactions.txt | mailx -s "Failed Transactions for date ${xxx}" ${EMAIL}
done

# one email
#
#
echo "Date [YYYY-MM-DD] : \c"
read xxx

grep "${xxx}.*Failed" $HOME/audit/* > /dev/null 2>&1 || grep "${xxx}.*Failed" $HOME/audit/* | uuencode failedtransactions.txt | mailx -s "Failed Transactions for date ${xxx}" ${EMAIL}
done