Hey I have a shell script that is like this:
This isn't working anyone know why? mail won't go out from subshell 2, however in subshell 1 I can send mail for any alerts.
in the first subshell I have a query on a database which is waiting on a correct response, if database is slow then
the simultaneous subshell running will have commands sleep and kill -$$ and send an email to me as an alert DB is going slowly!
Thanks. Let me know what your thoughts are.
---------- Post updated at 06:24 PM ---------- Previous update was at 06:14 PM ----------
Guys,
I will attempt your ideas today before eofday.
I however have probably not explained this properly:
I understand two subshells or 1 subshell and main command going same time.
BUT, I need to add a mail function in both.
what I am attempting is that: If the sleep 5 in subshell gets to end and the subshell its in kills -- -$$ ALL before my other main or simultaneous shell is doing some intensive/timeconsuming calculation against a SQL DATABASE -- Then Send and alert mail-s
I just need probably help getting errors directed taking everything into account in a mail command rather then how to terminate both shells.
So basically my logic is:
()
&
()
----
Shell1-
(do intensive calculations and
initialize variables for mail alert
Send mail
kill -- -$$
)
subShell2
(Sleep 5-10 depend
send mail alert if
finishes sleep saying something like (HEY WATCHOUT DATABASE SLOW, OR CRASHED!)
kill -- -$$
)
can someone elaborate how I can remove all possible errors from a mail -s function and ignore them cause in my tests yesterday I noted that thats where the hanging up is occurring, mail -s ONLY, the logic I think might be alright unless im missing something.
Again: if anyone knows how to dev/null mail properly can you add it to a simple echo blah/sleep5/sendmail/kill -- -$$ everything good while other subshell goes with (a sleep -faster time then 1st shell/ alert mail/and kill -- -$$ with other subshell
I can get one subshell to mail alerts by switching sleep times around but other wont.
Thus in the grand scheme of things,
-if my db is slow at responding -and sending an email with the variables I get from DB -and kill before other shell
-the other subshell will -sleep on side and after send mail and then kill all
Guys,
I will attempt your ideas today before eofday.
I however have probably not explained this properly:
I understand two subshells or 1 subshell and main command going same time.
BUT, I need to add a mail function in both.
what I am attempting is that: If the sleep 5 in subshell gets to end and the subshell its in kills -- -$$ ALL
Again, I'm not sure what 'kill -- -$$' is even trying to do. -- is not a valid option for kill, and killing your own shell would kill everything, leaving it not able to do anything. And -(number) would tell kill it's some strange kind of signal, not a process ID.
Quote:
before my other main or simultaneous shell is doing some intensive/timeconsuming calculation against a SQL DATABASE -- Then Send and alert mail-s
This is different from our suggestions how? Wait up to 5 seconds then kill, and if it had to be killed, email?
Quote:
So basically my logic is:
()
&
()
Once again, this logic doesn't make sense. & on a line by itself is meaningless, and -- why bother making a second subshell? You already have two shells, and you never background the second one anyway.
Quote:
Shell1-
(do intensive calculations and
initialize variables for mail alert
Send mail
kill -- -$$
)
subShell2
(Sleep 5-10 depend
send mail alert if
finishes sleep saying something like (HEY WATCHOUT DATABASE SLOW, OR CRASHED!)
kill -- -$$
)
Oh, I see -- you are trying to launch two scripts simultaneously. Each will kill the other if it finishes first.
This doesn't seem a good way to solve the problem, really. That's the very definition of "race condition". Even assuming good conditions, who can say whether one will kill the other in time? Who can say whether they will die cleanly?
And there's no point! It's an over-complicated, extra-wasteful, extra-sloppy, extra-error-prone version of the exact same algorithm: "Wait up to x seconds, then kill and send email".
If you're trying to avoid some sort of problem with this convoluted method, it'd be nice to know what problem, so that we can show you how to actually avoid it.
Quote:
Again: if anyone knows how to dev/null mail properly
I don't know what you're even trying to say here.
I will make my solution more complete in the hope you will actually try it:
If 'mail' is hanging, it might be a good idea to find out why.
Last edited by Corona688; 07-31-2014 at 02:21 PM..
Whats the difference between mail and mailx?
I'm trying to troubleshoot a problem where I can send mail from server A with this `echo $MESSAGE | mail -s "$SUBJECT" -r $FROM $RECIPIENTS` command but executing the same command from server B throws me this error (Both servers are RHEL)
... (1 Reply)
How can i send a mail when user login in unix ENV.
How can i know present use mailID??
Moved out of Contact Us Forum - Please Do Not Post Technical Questions in Non-Technical Forum(s) (1 Reply)
Hi guys...
I am busy writing a script to notify me via an mail if my application is down. I have done that.
Now I want this script to stop sending mails after five mails were sent but the script should keep on checking the application.
When the application is up again that count should be... (5 Replies)
i want to send an email from the unix machine to the windows machine.
now windows dont have any specified folder for the mail. mail has to be sent to the email-id like abc@xyz.com
unix machine itself can not directly send mail.
it has to be transferred via mail server. (11 Replies)
Hi,
I am want to send mails from my aix server using smtp adaptors.How to configure this? i tried with send mail command but it is failing,but what i try with my localhost(my desktop which is not using the aix server) machine i can send mails using the smtp adaptor(simply type telnet... (0 Replies)
Dear all,
how can i send mail using mailx or mail command?do i need to configure anything for sending mail?please help me.Its urgent.
the version i use is
Linux TDM 2.4.21-4.EL #1 Fri Oct 3 18:13:58 EDT 2003 i686 i686 i386 GNU/Linux
Thanks
Regards,
Pankaj (15 Replies)
Hi everyone!
I'm trying to create a database monitoring script that reads an alert file and sends an error message if it can 'grep' a particular string.
Is there a way to send this message to a mail client using SMTP?
Even better, is there any place on this site that has these kinds of... (5 Replies)