👤


Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

A shell script to run a script which don't get terminated and send a pattern from the output by mail

👤 Login to reply
 
Thread Tools Search this Thread Display Modes
    #8  
Old 03-12-2018
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 17 July 2018, 3:29 PM EDT
Location: Aachen, Germany
Posts: 13,065
Thanks: 449
Thanked 4,013 Times in 3,690 Posts
I don't have the slightest idea about how your ctftestdump works and what input it needs. Could an end, exit, or similar command be entered into querytas.txt?
Sponsored Links
    #9  
Old 03-12-2018
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 17 July 2018, 7:22 PM EDT
Location: San Jose, CA, USA
Posts: 11,407
Thanks: 649
Thanked 3,970 Times in 3,393 Posts
Try replacing testit_tas.sh with:
Code:
#!/bin/bash
IAm=${0##*/}
Tmpfile=/tmp/$IAm.$$

trap 'rm -f "$Tmpfile"' EXIT

./ctftestdump 10.240.56.1 8100 querytas.txt > "$Tmpfile" &
pid=$!
sleep 5
kill $pid
grep -F '5001=-46<TX>' "$Tmpfile"

In addition to normal output from the grep, this might also give you a line similar to the following:
Code:
testit_tas.sh: line 11: 20884 Terminated: 15          ./ctftestdump 10.240.56.1 8100 querytas.txt > "$Tmpfile"

which is bash's way of telling you that cftestdump was killed. If you find this line of output objectionable, you can get rid of it by redirecting stderr when you invoke testit_tas.sh:
Code:
./testit_tas.sh 2>/dev/null

but doing this will also hide any other diagnostic messages your script might provide. Do not do this until you know that the script is doing what you want it to do.
The Following User Says Thank You to Don Cragun For This Useful Post:
Sambit Sahu (03-13-2018)
Sponsored Links
    #10  
Old 03-13-2018
Sambit Sahu Sambit Sahu is offline
Registered User
 
Join Date: Aug 2017
Last Activity: 19 March 2018, 9:04 AM EDT
Posts: 12
Thanks: 6
Thanked 0 Times in 0 Posts
Hi Don,

This is just perfect. Now i just need to add the mail configuration to the script.

Thanks,
Sambit
    #11  
Old 03-13-2018
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 17 July 2018, 7:22 PM EDT
Location: San Jose, CA, USA
Posts: 11,407
Thanks: 649
Thanked 3,970 Times in 3,393 Posts
Quote:
Originally Posted by Sambit Sahu View Post
Hi Don,

This is just perfect. Now i just need to add the mail configuration to the script.

Thanks,
Sambit
Hi Sambit,
In post #7 you said that you could take care of the e-mail using cron as suggested by RudiC in post #6. What else needs to be done?
Sponsored Links
    #12  
Old 03-13-2018
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 17 July 2018, 3:29 PM EDT
Location: Aachen, Germany
Posts: 13,065
Thanks: 449
Thanked 4,013 Times in 3,690 Posts
I still find it difficult to believe that ctftestdump doesn't have a way to exit normally...
The Following User Says Thank You to RudiC For This Useful Post:
Don Cragun (03-13-2018)
Sponsored Links
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
C shell script wont terminated if i don't modify the shebang pilistar0222 Shell Programming and Scripting 5 11-28-2017 10:28 PM
How to write this script:- check output word and send a mail? manalisharmabe Shell Programming and Scripting 20 04-22-2014 05:45 AM
Run sql script and send to mail if not empty? Astrocloud Shell Programming and Scripting 1 08-12-2013 12:12 PM
how to run a script using cron job and send the output as attachment via e-mail using unix vidhyaS Shell Programming and Scripting 8 06-09-2011 02:20 AM
Send e-mail in Shell script annelisa Shell Programming and Scripting 1 07-13-2006 07:35 AM



All times are GMT -4. The time now is 10:37 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?