LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to set timeout for mailx (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-set-timeout-for-mailx-4175589042/)

halfmoonhalf 09-08-2016 05:40 PM

how to set timeout for mailx
 
Hi all,
newbie here.
I am using Heirloom mailx 12.4 in centos 6.6
sometimes i find that when I send email though mailx it just freezes for more than a minute before giving a timeout error.
My question is: How to set send email timeout to 3 sec?
thanks!

ps: I have been searching for a full guid for setting up ~/.mailrc configuration file and never make it... Any hint will be much appreciate. I went through "man mailx" and it doesn't seem to discuss much about the conf file, does it?
Thanks!

halfmoonhalf 09-08-2016 06:28 PM

this might be a walkaround
 
this might be a walkaround:
timeout 3 bash -c "echo "body" | mailx -S sendwait -s "title" name@gmail.com"

1. sendwait
manul: When sending a message, wait until the mail transfer agent exits before accepting further commands. If the mail transfer agent returns a non-zero exit status, the exit status of mailx will also be non-zero.
My thinking: so sendwait is to ask mailx to do email sending in only one process instead of starting a child process. I think only in this way the "timeout" control is meaningful or else "timeout" is only checking the wrapping program. is this correct?

2. the command works but it is better to use
timeout 3 bash -c "echo 'body' | mailx -S sendwait -s 'title' name@gmail.com"
the thing I dont quit understand is how does the double-quote inside double-quote work in this command?
I can only find this in "man bash":
-c string If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0.
Can anybody explain more on this?

3. I use bash -c because there is pipe inside the mail command. Is this the only solution for piping?


All times are GMT -5. The time now is 12:18 AM.