Background
Playing around with Linux and exploring sending emails.
Tool
mail.
Option
Option | Explanation | Sample |
---|---|---|
-a | Attachment | diskfree.txt |
-b | Bcc | pier@dekalb.org |
-c | Cc | joey@abc.com |
-r | From | Sally in Accounting |
-s | Subject | Disk Free |
Recipient Address | toni@nobody.com |
Sample
Sample #1
Outline
- Run command
- Command:- df ( diskfree )
- Capture command into a text file ( diskfree.txt )
- Attach command output ( diskfree.txt )
- The subject is “disk free on @HOSTNAME“
- The from field should be set Susan
- The recipients are listed at the end of the command
- In our case dba@companya.com
Code
df -h > diskfree.txt | echo "" | mail -s "disk free on $HOSTNAME " -r "Susan" -a diskfree.txt dba@companya.com
Sample #2
Outline
- Run command
- Command:- df ( diskfree )
- Capture command into a text file ( diskfree.txt )
- Send command output as email’s body
- The subject is “disk free on @HOSTNAME“
- The from field should be set Susan
- The recipients are listed at the end of the command
- In our case dba@companya.com
Code
df -h > diskfree.txt | mail -s "disk free on $HOSTNAME " -r "Susan" -a diskfree.txt dba@companya.com < diskfree.txt
References
- die.net
- mail(1) – Linux man page
Link
- mail(1) – Linux man page