-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatusMail.sh
executable file
·70 lines (51 loc) · 1.72 KB
/
statusMail.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
: <<'END'
Script to sent statusmail to myself from any computer with the script in cron
and ssmtp installed.
Requirements:
* ssmtp
* ~/repos/configs/ssmtp.conf
Edit crontab:
crontab -e
Add this:
0 7 * * * /home/kiro/repos/scripts/statusMail.sh
This will execute the statusMail script each day at 07:00.
And update the /etc/ssmtp/ssmtp.conf with the config file.
END
EMAILMESSAGE="/tmp/emailmessage.txt"
if [ -e "$EMAILMESSAGE" ]
then
rm $EMAILMESSAGE
fi
hostname=`hostname`
echo "To:[email protected]
From:[email protected]
Subject: Status from '$hostname'
" >>$EMAILMESSAGE
#echo "start"
# add additional message body here.
# 'ip987321' is the name of the temp file used to store the page containing my current ip.
# the perl program prints the ip addresses in the file.
# then the temp file is removed.
externalIP=`wget -q -O ip987321 http://checkip.dyndns.org/ && perl /home/kiro/repos/scripts/perl/echoAllIPsFromFile.pl ip987321`
echo "External IP: $externalIP" >> $EMAILMESSAGE
rm ip987321
#echo "between ips"
# get the local IP
localIP=( $(/sbin/ifconfig | grep -A 2 "eth0" | grep -oP "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}") )
echo "Local IP: $localIP" >> $EMAILMESSAGE
# this used to work.
#lynx --dump http://ipecho.net/plain >> $EMAILMESSAGE
# print number of pending updates to the message body
#echo "updates"
echo "" >> $EMAILMESSAGE
echo "Updates: " >> $EMAILMESSAGE
sudo apt-get update >> /dev/null
echo `apt-get -s upgrade | grep "newly install"` >> $EMAILMESSAGE
# print login status and session data to message body
#echo "logins"
echo "" >> $EMAILMESSAGE
echo "Status: " >> $EMAILMESSAGE
w >>$EMAILMESSAGE
# send an email using /bin/mail
/usr/sbin/ssmtp [email protected] < $EMAILMESSAGE