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
How to answer pointed "are you quitting" questioning when I don't want them to suspect
Why can Shazam do this?
Why is Grand Jury testimony secret?
JSON.serialize: is it possible to suppress null values of a map?
Are there any other methods to apply to solving simultaneous equations?
Confusion about non-derivable continuous functions
On the insanity of kings as an argument against Monarchy
How can I fix this gap between bookcases I made?
How long do I have to send payment?
Should I use my personal or workplace e-mail when registering to external websites for work purpose?
What tool would a Roman-age civilization have to grind silver and other metals into dust?
Manuscript was "unsubmitted" because the manuscript was deposited in Arxiv Preprints
A poker game description that does not feel gimmicky
In microwave frequencies, do you use a circulator when you need a (near) perfect diode?
aging parents with no investments
I see my dog run
Could JWST stay at L2 "forever"?
Patience, young "Padovan"
If Wish Duplicates Simulacrum, Are Existing Duplicates Destroyed?
Lethal sonic weapons
Inline version of a function returns different value then non-inline version
Feasability of miniature nuclear reactors for humanoid cyborgs
The difference between dialogue marks
Why Did Howard Stark Use All The Vibranium They Had On A Prototype Shield?
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;
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
New contributor
anmoreira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
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
New contributor
anmoreira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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
add a comment |
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
New contributor
anmoreira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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
bash shell-script grep scripting
New contributor
anmoreira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
anmoreira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 2 days ago
terdon♦
134k33269449
134k33269449
New contributor
anmoreira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Apr 3 at 17:49
anmoreiraanmoreira
63
63
New contributor
anmoreira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
anmoreira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
anmoreira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
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
add a comment |
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
add a comment |
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
);
);
anmoreira is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
anmoreira is a new contributor. Be nice, and check out our Code of Conduct.
anmoreira is a new contributor. Be nice, and check out our Code of Conduct.
anmoreira is a new contributor. Be nice, and check out our Code of Conduct.
anmoreira is a new contributor. Be nice, and check out our Code of Conduct.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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