A shell script to run a script which don't get terminated and send a pattern from the output by mail
Hi Guys,
I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those lines over email.
Also, the script abc.sh need to be terminated as it don't get terminated. Now, I am running the script and have to do CTRL+C to get to next prompt.
Whenever you start a thread in this forum it is a good idea to tell us what operating system and shell you're using.
We could be lazy and say that you should rewrite abc.sh to do what it is supposed to do and exit instead of looping forever, but since we have no idea what it is supposed to do, this might not be possible.
If abc.sh runs forever, it is not possible to write a script that runs it and then checks the contents of a file. One could start it asynchronously and occasionally check its output file, but since you haven't told us what output file(s) it creates nor what output you're hoping to find, it is hard for us to guess at how to do that.
If you showed us the contents of abc.sh (in CODE tags), showed us the output it produces (in CODE tags), and showed us the email you're hoping to produce (in CODE tags); we might have a much better chance of helping you.
I will explain it in a better way. Linux is the operating system and using bash shell.
So the requirement is as below:
We have a script called testit_tas.sh to test the servers which don't get terminated and we pass CTRL+C to kill it everytime. Below is the content of the script:
So when we run this script (./testit_tas.sh) we get this below output on the terminal and it don't get completed. So we kill it manually
So from above output, we need to search the lines for 5001=-46<ETX> and capture these lines. -46 is error. So we want to capture this and alert only these lines over email to specific people.
Once this script is written, we will schedule it in crontab which will run 3 times to do this check.
Also, I know that to abort the script we can find the process id and kill it but am not sure how to include this.
On top of what Don Cragun asked, there are some more informations that could help to taylor a solution:
Is ctftestdump your (company's) own command or script, i.e. are you responsible and in a position to analyse / modify it? How is it to be terminated under normal circumstances? Does it deliver a (meaningful?) exit status? Is that reliable and could be exploited for your purpose?
You seemingly post stdout from your command / script - what is querytas.txt for? After how many 5001=-46<ETX> occurrences should the new script terminate / send the e-mails? How long should it wait for that string? Is 46 the only error number? Is <ETX> that literal ASCII string or the ASCII control code "end of text" (0x03)? cron sends e-mails with a job's output when it finishes - would that be sufficient to accomplish the task?
BTW: The shebang you tried to use is the wrong way round. Make it #!.
Is
your (company's) own command or script, i.e. are you responsible and in a position to analyse / modify it? How is it to be terminated under normal circumstances? Does it deliver a (meaningful?) exit status? Is that reliable and could be exploited for your purpose?
I think its a binary file which accepts arguments and we cannot modify it. We cant exploit it.
what is
for?
It holds the queries/requests which need to be sent. After how many
occurrences should the new script terminate / send the e-mails? How long should it wait for that string? Is 46 the only error number?
When we run the
, it gives the output instantly. There is nothing like we need to wait for some number of occurences of -46. It gives the output instantly and we can terminate it instantly. Below is some information about the output:
So there are three possibilities for the output (remember the response will have the 5026=xxxxx which matches the request)
1. Data is returned
the first line is the data itself, with the 5026=117032
the second line is the response terminator 5001=0
2. Error -46 is returned
This is what we want to capture and send an alert over email.
3. A different error is returned.
In this case the error is -203. There could be other errors. This is not urgent issue and we don't need to capture it for now.
cron sends e-mails with a job's output when it finishes - would that be sufficient to accomplish the task?
It would be better if we can just report the lines(represents which markets) contains
(Error) so that further investigation can be done.
So, in short we need to run the
3 times a day to check the server and if there are error (-46) in the output, we will report specific user over email. I hope, I was able to define the requirement
Hmm - it's not quite clear how the command terminates, or why it does not. Nor, if the number of error lines is predefined or open. Howsoever, how far would
in crontab get you? It extracts the required error from the output and mails it to userlist. Adapt the date / time fields according to your needs.
This we can do but the problem is how we can terminate. I have tried few things.
Below is the output when I am just running the script.
Below are the errors:
So as per your thought, we can do this in cron:
And we get the desired output which we can send it over email. But the issue is how we can terminate. Is it some way we can kill the running PID here. This can be resolved then.
Hello Team .
I am working a health check script ( bash) to run on linux server ( RedHat) and requirements are
1. The o/p of script need to be send to two diff files . I am testing with tee command . But I am not successful yet , any recommendations if that is the right approach ?
2. The same... (2 Replies)
Hi all, I'm new to shell script
i wrote some shell script for my colleague, everyone is fine,except on user
we are using VNC viewer to work
and there are some script start with shebang #! /bin/csh
there is an user will not terminate after running the script even if a hello world
i need... (5 Replies)
HI Guys,
I am writing one shell script to send the mail alert to some email id's if the file not modified in last 10 mins but its not working, I believe MTIME is null string is wrong . can you please assist me on this.
script :-
filename="abc.txt"
echo "Filename is $filename"... (1 Reply)
Hi Guys,
I am not Good at scripting.
I need to write a script such that if output of command shows the particular word in output then send mail to abc@compay.com
-bash-3.2$ ps -ef | grep bpbkar
root 6040 1 0 13:05:19 ? 0:00 bpbkar -r 2678400 -ru root -dt 47395 -to 0... (20 Replies)
Thanks again for helping me out.
I was wondering if anyone else has encountered this issue.
I have a SQL script that produces a list -however we are only interested in that list if the length is not zero
Here is the sql file named dailyBalance.sql
select * from Balance where... (1 Reply)
how to run a script using cron job and send the output as attachment via e-mail using unix. please help me.
how my cron job entry should be?
As of now my cron job entry is to run the script at specific time,
15 03 * * * /path/sample.sh | mail -s "Logs" email_id
In the above entry, what... (8 Replies)
Hi ,
I need to prepare a script which will check my database with specific to particluar table. If the row count exceeds a certain limit, i need to send a mail to a set of Recipients.
Being new to unix, please guide me to complete this task.
Advance thanks,
Sekar. (4 Replies)
Hi,
I need a shell script which runs in the backround for all the 24 hours and send a mail to us regarding the output of the prstat command when the load average increase above certain percent.
kindly help me on this...... (1 Reply)