Click to See Complete Forum and Search --> : Fails to pass Variables & Does not output Tables...


danj_aas_cns
12-12-2004, 01:49 PM
Does anyone have any ideas as to what is wrong with this script? It has me completely befuddled as everything is there & is set up the way that it should be...


#!/bin/bash
USER=<name>@<domain>.<tld>
DATE='date "+%a %b %e"'
TIME='date "+%T"'
TABLE='/sbin/iptables -L'

MAIL=/bin/mail

$MAIL $USER << EOF

Subject: IPTables Report

This is the current status of your IP Tables as of the last window.

Date: $DATE
Time: $TIME

--- Results ---

$TABLE

EOF

Uranus
12-12-2004, 02:00 PM
Put the value of DATE, TIME, and TABLE in backticks instead of single quotes (` instead of '). Or use $(command) - I prefer this one even more.
<name>@<domain>.<tld>
^^ What does that do?
I don't know whether mail outputs the message it sends - I've never used mail. I think if the above isn't substituted by a username it will also not mail correctly.
HTH
Sam

danj_aas_cns
12-12-2004, 02:03 PM
Originally posted by Uranus

<name>@<domain>.<tld>
^^ What does that do?
I don't know whether mail outputs the message it sends - I've never used mail. I think if the above isn't substituted by a username it will also not mail correctly.
HTH
Sam

I typically won't post e-mail addresses to posts unless it's necessary :)

danj_aas_cns
12-12-2004, 02:31 PM
Well, the script works now... Sort of. I still need the script to post the date and time.

The script is intended to generate an e-mail whenever the tables are reloaded or the server is restarted.

fatTrav
12-12-2004, 02:40 PM
Here is a crappy script I wrote to email me whenever my exernal IP changes. Email address were changed to protect the innocent.#!/bin/bash
# Script that emails me our real IP
# Great for an hourly cron job.
#set -x
email() {
SENDMAIL=/usr/sbin/sendmail
REC="travis@hisemailaddress"
FROM="travis@grendel.org"

$SENDMAIL -f $FROM $REC << EOF
Subject: IP Update

Our IP is: `lynx -dump http://checkip.dyndns.org/ | awk --posix '{ print $4 }'`.

EOF
exit 0;
}

IP=`lynx -dump http://checkip.dyndns.org/ | awk --posix '{ print $4 }'`
OLD=`cat /etc/cron.hourly/ourip`

if [ $IP != $OLD ]; then
rm /etc/cron.hourly/ourip
echo $IP >> /etc/cron.hourly/ourip
email
fi

Just put in the 'body' of the email something like I have with the lynx --dump command (but for date). I run this hourly (it just sits in /etc/cron.hourly) which might be a good setup for your script.

Uranus
12-12-2004, 04:42 PM
Originally posted by danj_aas_cns
I typically won't post e-mail addresses to posts unless it's necessary :)
Ow man... I can't believe this :D
/Sam - such a moron today