Most of the times we need the data generated from output of scripts. It will be useful if we can automate the process of collecting this generated data on the fly and starts sending it to our email inbox which the Linux mail command.
Linux mail command can be used with the output from scripts as shown below
Here, the output from script
Attachments can also be sent with an option "-a" passing to linux mail command.
Direct execution of mail command prompts an user for entering the carbon copy field followed by body content. User needs to compose an email and once done, user needs to press "CTRL+D" which prompts the mail command about the completion of body content.
| mail options | Description |
|---|---|
| -s | For specifying the subject of an email |
| -a | For uploading an attachment files |
| -c | To specify Carbon Copy recipients |
| -b | To specify Blind Carbon Copy recipients |
| -aFrom | To specify the senders email address |
Linux mail command can be used with the output from scripts as shown below
./run.csh | mail -s"Output" abc@xyz.com
Here, the output from script
run.csh will be the body content of an email with the subject of email as "Output" and recepient of the email will be abc@xyxAttachments can also be sent with an option "-a" passing to linux mail command.
echo "Mail content goes here" | mail -a"data.txt" -s"Subject" abc@xyz.com
data.txt file is sent as an attachment to abc@xyz.com recipient.
Direct execution of mail command prompts an user for entering the carbon copy field followed by body content. User needs to compose an email and once done, user needs to press "CTRL+D" which prompts the mail command about the completion of body content.
mail -s"Subject" abc@xyz.com Cc: Enter email ids with commas if required OR press Enter Now start composing the email content Line by line Once completed, press Ctrl + D for sending email
