0

Following K7AAY and 0xSheepdog advice I'll rephrase.

I need to create a bash script where it will grep a log file that is generated daily when a file is sent in a range of time of the day.

The filename is usually something like YYYYMMDD_HHMMSS_SEND_FILENAME_TO_HOST.log

(This log file is generated from CFTutil, a file transfer application)

In this log file I need the script to find the following string which I'm able to do:

SUCCESSFUL

Now, the script must send an email if the file is transferred successfully in between x and y time. An email must be sent if the file is not sent in between x and y time. An email must be sent if the file is not sent if the file is sent after the y.

I was able to the following script but I am stuck and do not think this is the best approach. Since this script will only search for one file and I need to do this to 15 files.

I though of creating a script for each file and scheduling with a cron job but I would like to to do all in one script so I could run whenever I want and receive a report of the status of each file in it.

The script at the moment is like this:

#!/bin/bash
dt=$(date +"%Y%m%d")
HHMM=$(date '+%H:%M')

if
        find ./ -newermt "$dt 21:30:00" ! -newermt "$dt 23:50:00" -name "$dt_*SEND_FILE1_TO_HOST.log" -exec grep -i successful {} \;
then
#       mail -s "File File1 Transmission Report" QA@mycomapny.com <<< "File was generated and successfully sent at $HHMM";
        echo "Sucess"
elif
        find ./ -newermt "$dt 21:30:00" ! -newermt "$dt 23:50:00" -name "$dt_*SEND_FILE1_TO_HOST.log" -exec grep -i unsuccessful {} \;
then
#       mail -s "File File1 Transmission Report" QA@mycomapny.com <<< "File was generated but unsuccessfully sent at $HHMM";
        echo "Error"
elif
        find ./ -newermt "$dt 21:30:00" ! -newermt "$dt 23:50:00" -name "$dt_*SEND_FILE1_TO_HOST.log" -exec false {} \;
then
#        mail -s "File File1 Transmission Report" QA@mycomapny.com <<< "File not generated in due time Please verify ASAP";
        echo "Not Found"
fi

newermt will not work and I am still trying to figure out how can I search the file in range of time.

CFTUTIL is a tool monitors the reception of the files and the distributes between hosts. It constantly monitor directories for files and when a file is received it will distribute and archive. While doing this it will generate a log for each host.

How can I possibly create a script like this.

  • 1
    Welcome to UNIX&Linux Stack Exchange. You don't really have a question in this post. You say "I need a bash script..." Are you asking for someone to create this for you? That isn't likely to get a positive response. If you have tried writing a bash script and it fails on particular steps, outlining those details and explaining what hasn't worked, and asking for specific pointed guidance is more likely to receive feedback and suggestions. – 0xSheepdog Apr 3 at 18:27
  • 1) Please click edit & add in the original question what you're written so far. It's best,to expand your 1st ?, which assures all can see the change, rather than reply-by-Comment. Comments pile up, & scroll off the screen after a while... .2) You also cited using tail. How far from the last line is "FILE TRANSFER : SUCCESSFUL" found?... 3) Lastly, you refer to the time a file is sent... does CFTutil know the time the sending PC transmits? If not, suggest changing 'time set" to "time received", for how does the receiving PC know the send time? – K7AAY Apr 3 at 18:34
  • thank you for your advices – anmoreira Apr 4 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.