Claim your Biolink Click Here
0 like 0 dislike
851 views
in Computers & Internet by | 851 views

1 Answer

0 like 0 dislike
you can send mails from your shell scripts. Here’s a simple shell script that gives you a reading of the usage of space on your partitions and mails the data to you.
 
    #!/bin/bash
    df -h | mail -s “disk space report” name@domain.com
 
Save these lines in a file on your Linux server and run it. You should receive a mail containing the results of the command. If, however, you need to send more data than just this you will need to write the data to a text file and enter it into the mail body while composing the mail. Here’s and example of a shell script that gets the disk usage as well as the memory usage, writes the data into a temporary file, and then enters it all into the body of the mail being sent out:
 
    #!/bin/bash
    df -h > /tmp/mail_report.log
    free -m >> /tmp/mail_report.log
    mail -s “disk and RAM report” name@domain.com < /tmp/mail_report.log
 
Now here’s a more complicated problem. You have to take a backup of a few files and mail then out. First the directory to be mailed out is archived. Then it is sent as an email attachment using mutt. Here’s a script to do just that:
 
    #!/bin/bash
    tar -zcf /tmp/backup.tar.gz /home/calvin/files
    echo | mutt -a /tmp/backup.tar.gz -s “daily backup of data” name@domain.com
 
The echo at the start of the last line adds a blank into the body of the mail being set out.
 
This should get you started with sending mails form the Linux command line and from shell scripts. Read up the “man page” for both mail and mutt for more options.
by

Related questions

0 like 0 dislike
1 answer
1 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
1 like 0 dislike
1 answer
1 like 0 dislike
1 answer
1 like 0 dislike
1 answer
1 like 0 dislike
1 answer
0 like 0 dislike
1 answer
1 like 0 dislike
1 answer

Where your donation goes
Technology: We will utilize your donation for development, server maintenance and bandwidth management, etc for our site.

Employee and Projects: We have only 15 employees. They are involved in a wide sort of project works. Your valuable donation will definitely boost their work efficiency.

How can I earn points?
Awarded a Best Answer 10 points
Answer questions 10 points
Asking Question -20 points

1,312 questions
1,473 answers
569 comments
4,809 users