sending email as background process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sending email as background process
# 1  
Old 08-14-2009
sending email as background process

Hi All,

Solaris
Bash v3x

I have a script that accepts an error code, and if the error code is not 0 then an email is sent using mailx to details the error.

I want to be able to implement the functiuonlity whereby i can send the email in a background process so the script can continue with other logic
and if the email has not completed say within 30 seconds then to abort

does anyone have a code snippet that I could use/ammend?


something like...


#!/bin/bash

<< normal code>>

<<start background process here>>
echo “message” | mailx -s “<Subject>” <recipient mail address>
if not responsing or email not sent within 30 seconds then abort with error message

<< continue normal code here>>

any ideas much appreciated..

Kind Regards
Satnam
# 2  
Old 08-14-2009
Hi.

One way would be to write a small function:

Code:
MAX_TIME=30

function CheckAndKill {
  sleep $MAX_TIME
  [ "$(ps | awk '$1 == '$1)" ] && echo "Killing process $1" && kill -9 $1
}
....
....
echo “message” | mailx -s “<Subject>” <recipient mail address>
CheckAndKill $! &

# 3  
Old 08-17-2009
Includes Background Process?

Hi Scott

Thanks for the reply..looks intersting and am trying it.. any ideas how I would ammend it to execute the mailing to a background process?

Kind regards
Satnam

---------- Post updated at 06:26 PM ---------- Previous update was at 06:06 PM ----------

Hi Scott,

Just 2 questions:
1. The commad CheckAndKill $! & ... is the & a 2nd parameter, if so not sure what it represents?
Regards
Satnam
# 4  
Old 08-18-2009
Hi.

The & will run the function in the background.

You can add a & to the end of your mail command too (sorry I forgot to add that in my original reply).

Cheers.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Make background process interact with fg process

Hi, I have written a menu driven shell script in which as per the choice, I run the another script on background. For eg: 1. get info 2)process info 3)modify info All the operations have different scripts which i schedule in background using &. However I wish to display the error... (0 Replies)
Discussion started by: ashima jain
0 Replies

2. Shell Programming and Scripting

Using top command to email if process is exceeding 25% and sending an email alert if so

This is my first time writing a script and Im having some trouble, Im trying to use the top command to monitor processes and the amount of CPU usage they require, my aim is to get an email if a process takes over a certain percentage of CPU usage I tried grep Obviosly that hasnt worked, Any... (8 Replies)
Discussion started by: jay02
8 Replies

3. Shell Programming and Scripting

Need help regarding sending sleep to background

Hi, can we print anything, when sleep is running..? like printing dots(.. . . . . . . . .) to indicate that some process is going on...? i mean, can we send sleep to background, proceed with printing, till sleep is going on... in s single step. I have written a funtion to solve this. ... (1 Reply)
Discussion started by: Dpu
1 Replies

4. Shell Programming and Scripting

How to put FTP process as a background process/job in perl?

Hi, I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming. So i want try putting FTP part as a background process. I am unaware how to do... (5 Replies)
Discussion started by: vanitham
5 Replies

5. Shell Programming and Scripting

Sending key events to background script

Hi, short summary: I need to send keystrokes from USB keyboard to background (bash-)script. I guess I have to use read on the right devive board but how and which? My details: I got a small home server with some VMs using KVM/Qemu, all are suse 11.3. But in general I work on a client... (0 Replies)
Discussion started by: Snowman
0 Replies

6. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

7. Linux

sending an email

I have used an already-built ActiveX control to send email from my asp web pages. One of the parameters I fill is FromName which defines the tittle the recipient will see in the From entrance in his Inbox. Now I´m trying to use mail to send an email from a Shell but I haven´t found the... (1 Reply)
Discussion started by: RandomAccess
1 Replies

8. UNIX for Dummies Questions & Answers

sending email

hi, is there any possiblity to send email from the command prompt, for eg i want to send alert to any mail id like /data/logs is 80% to my hotmail account , xxx@hotmail.com is this really possible,, if not, then what are the prerequistes need to do this (1 Reply)
Discussion started by: vasikaran
1 Replies

9. UNIX for Dummies Questions & Answers

Sending email

I have an Solaris 8 machine running a managment application. One of the features of this application is to configure alarm forwarding to an email undress. When i configured the application to do that, it asked me only about the recipient email address. Quesiton: how to configure my Solaris 8... (7 Replies)
Discussion started by: bcheaib
7 Replies

10. Shell Programming and Scripting

capture the process id when starting a background process

Hello all, How do I start a background process and save the process id to a file on my system. For example %wait 5 & will execute and print the process id. I can't figure out how to get it to a file. I've tried: > filename 0>filename 1>filename. Any assistance is most appreciated. Thanks, Jim... (10 Replies)
Discussion started by: jleavitt
10 Replies
Login or Register to Ask a Question