| 1 | #!/bin/sh |
| 2 | # self-mailer.sh: Self-mailing script |
| 3 | |
| 4 | adr=${1:-`whoami`} # Default to current user, if not specified. |
| 5 | # Typing 'self-mailer.sh [email protected]' |
| 6 | #+ sends this script to that addressee. |
| 7 | # Just 'self-mailer.sh' (no argument) sends the script |
| 8 | #+ to the person invoking it, for example, [email protected]. |
| 9 | # |
| 10 | # For more on the ${parameter:-default} construct, |
| 11 | #+ see the "Parameter Substitution" section |
| 12 | #+ of the "Variables Revisited" chapter. |
| 13 | |
| 14 | # ============================================================================ |
| 15 | cat $0 | mail -s "Script \"`basename $0`\" has mailed itself to you." "$adr" |
| 16 | # ============================================================================ |
| 17 | |
| 18 | # -------------------------------------------- |
| 19 | # Greetings from the self-mailing script. |
| 20 | # A mischievous person has run this script, |
| 21 | #+ which has caused it to mail itself to you. |
| 22 | # Apparently, some people have nothing better |
| 23 | #+ to do with their time. |
| 24 | # -------------------------------------------- |
| 25 | |
| 26 | echo "At `date`, script \"`basename $0`\" mailed to "$adr"." |
| 27 | |
| 28 | exit 0 |
| 29 | |
| 30 | # Note that the "mailx" command (in "send" mode) may be substituted |
| 31 | #+ for "mail" ... but with somewhat different options. |