Building a script to find a file if exists and grep for a string The 2019 Stack Overflow Developer Survey Results Are Inecho string >> file does not workfind parent string based on regexWhile Read loop to emailgrep script - output lines at the same time into echoCalling a file with variable file name in bash scriptreplace the empty fields from the output of “grep” with a stringparallel processing reading from a file in a loopA string from my script in the LOG file in BackupPC:?Append to the top in a log fileGrep latest file for string and alert / email if found

Did 3000BC Egyptians use meteoric iron weapons?

Is flight data recorder erased after every flight?

Why isn't the circumferential light around the M87 black hole's event horizon symmetric?

FPGA - DIY Programming

What tool would a Roman-age civilization have for the breaking of silver and other metals into dust?

"as much details as you can remember"

How to type this arrow in math mode?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

Is bread bad for ducks?

What is the meaning of the verb "bear" in this context?

Why did Acorn's A3000 have red function keys?

Loose spokes after only a few rides

Why do some words that are not inflected have an umlaut?

What is the meaning of Triage in Cybersec world?

Why hard-Brexiteers don't insist on a hard border to prevent illegal immigration after Brexit?

Why can Shazam fly?

If a Druid sees an animal’s corpse, can they wild shape into that animal?

What does ひと匙 mean in this manga and has it been used colloquially?

Can one be advised by a professor who is very far away?

Have you ever entered Singapore using a different passport or name?

Should I use my personal e-mail address, or my workplace one, when registering to external websites for work purposes?

Can you compress metal and what would be the consequences?

When should I buy a clipper card after flying to OAK?

How to deal with fear of taking dependencies



Building a script to find a file if exists and grep for a string



The 2019 Stack Overflow Developer Survey Results Are Inecho string >> file does not workfind parent string based on regexWhile Read loop to emailgrep script - output lines at the same time into echoCalling a file with variable file name in bash scriptreplace the empty fields from the output of “grep” with a stringparallel processing reading from a file in a loopA string from my script in the LOG file in BackupPC:?Append to the top in a log fileGrep latest file for string and alert / email if found



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















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.










share|improve this question



















  • 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

















-1















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.










share|improve this question



















  • 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













-1












-1








-1








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.










share|improve this question
















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.







bash shell-script grep scripting






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 7 at 15:32









terdon

134k33269449




134k33269449










asked Apr 3 at 17:49









anmoreiraanmoreira

63




63







  • 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












  • 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







1




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





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






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





thank you for your advices

– anmoreira
Apr 4 at 23:37










0






active

oldest

votes












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f510333%2fbuilding-a-script-to-find-a-file-if-exists-and-grep-for-a-string%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f510333%2fbuilding-a-script-to-find-a-file-if-exists-and-grep-for-a-string%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.