Also Read: 101-500: Linux Administrator - 101 (LPIC-1 101)
Without any further ado, here is the Linux shell script that sends the email. (Note that although I keep writing "Linux mail", this should also work on other Unix systems.)
Example Linux shell script - sending mail
Here's the source code for the Linux shell script that sends the email message out every day:
#!/bin/sh
cd /home/lpicentral/bin
echo "
DO NOT REPLY TO THIS EMAIL MESSAGE.
This is a list of the current customer directories installed on our server.
Please make sure they are all billed.
" > listOfWebSites
ls -1 /customers >> listOfWebSites
mail -s "Current customer directories on our server" kim@herdomain.com < listOfWebSites
That script creates a file named listOfWebSites, then sends that file via the standard Linux mail command.
Corresponding Linux crontab entry
Here is the crontab entry that I use to send this email message every day. If you're familiar with the crontab format you should be able to easily figure out the date and time this information is mailed to here.
30 7 12 * * /home/lpicentral/bin/mailWebSitesToKim
I thought this was a pretty decent use of shell scripting and the built-in Linux mail command. Notice how easy the Unix operating system and redirection operators make this.
0 comments:
Post a Comment