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.
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 :
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.