Ubuntu/Scripts
From r00tedvw.com wiki
(Difference between revisions)
Line 13: | Line 13: | ||
#define variables | #define variables | ||
− | + | HOSTNAME=`hostname` | |
from="$HOSTNAME"'@sender domain.com' | from="$HOSTNAME"'@sender domain.com' | ||
to='recipient address' | to='recipient address' | ||
Line 46: | Line 46: | ||
mail_input | telnet $recipient_mx 25 || exit | mail_input | telnet $recipient_mx 25 || exit | ||
exit | exit | ||
+ | |||
+ | ====Learned==== | ||
+ | *you cannot define a variable as the same exact spelling of the command. ie. hostname≠`hostname` |
Revision as of 00:22, 22 June 2014
Contents |
Email current IP address
Variables needing to be defined:
- sender domain (@sennder domain.com)
- recipient (recipient address)
- recipient mail exchanger (recipient mail exchanger)
Variables automatically defined
- HOSTNAME - defined by using the hostname command
- DATE - defined by using the date command
Code
#!/bin/bash -x #define variables HOSTNAME=`hostname` from="$HOSTNAME"'@sender domain.com' to='recipient address' recipient_mx='recipient mail exchanger' DATE=`date` messageid='[email protected]' IP=$(curl checkip.dyndns.org|awk '/Address:/ {print$6}'|sed 's/<.*/ /') #function containing mail commands. Contains enough RFC required fields to satisfy gmail's requirements to allow the message, though it may be detected as spam if you do not have a SPF record. function mail_input { sleep 1 echo 'ehlo test.com\n' sleep 0.5 printf 'mail from:<'"$from"'>\n' sleep 1 printf 'rcpt to:<'"$to"'>\n' sleep 1 printf 'data\n' sleep 0.5 printf 'Return-Path: <'"$from"'>\n' printf 'Date: '"$DATE"'\n' printf 'Message-ID: <'"$messageid"'>\n' printf 'Subject: test\n' printf 'From: <'"$from"'>\n' printf 'To: <'"$to"'>\n' printf "$HOSTNAME"' ip address= '"$IP"'\n' printf '.\n' printf 'quit' } #sending mail with mail_input function mail_input | telnet $recipient_mx 25 || exit exit
Learned
- you cannot define a variable as the same exact spelling of the command. ie. hostname≠`hostname`