From c4ec24deffb36316cbd018b94586e53e60ce6809 Mon Sep 17 00:00:00 2001 From: David Beniamine <david.beniamine@imag.fr> Date: Mon, 16 Jan 2017 16:52:35 +0100 Subject: [PATCH] some documentation --- Readme.md | 24 ++++++++++++++++++++++++ getip.sh | 40 ++++++++++++++++++++++++++++++++++++++++ healthReport.sh | 4 ++-- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 Readme.md create mode 100755 getip.sh diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..9744f55 --- /dev/null +++ b/Readme.md @@ -0,0 +1,24 @@ +# Script utils + +## Healthreport + +## Dependencies + +systemd +aptitude +debian-goodies +ufw +cpufreq-utils +lm-sensors +pandoc + + +The following scripts must be in the same directory + + getip.sh + +## Install + +Add the crontab entry + + 0 7 * * 1 /path/to/healthReport.sh -m "Weekly health report" 2> /dev/null diff --git a/getip.sh b/getip.sh new file mode 100755 index 0000000..32db8eb --- /dev/null +++ b/getip.sh @@ -0,0 +1,40 @@ +#!/bin/bash +isIP() +{ + ret=1 + ip=$1 + if [[ $ip=~^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] + then + OIFS=$IFS + IFS='.' + ip=($1) + IFS=$OIFS + [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] + ret=$? + + fi + return $ret +} +#Parse IP from sfr/orange box +myip=$(curl $(/sbin/route | grep default | /usr/bin/awk {'print $2'}) \ + | grep "Adresse IP" -A 1 | /usr/bin/tail -n 1 |\ + sed -e "s/.*>[^0-9]*\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)[^0-9]*<.*/\1/g") +if isIP $myip +then + echo "External IP is : $myip" + exit 0 +fi +#Old bad method using hosts, usable if the first method fail +Hosts=("icanhazip.com" "ident.me" "ipecho.net/plain" \ + "whatismyip.akamai.com" "tnx.nl/ip" "myip.dnsomatic.com" \ + "ip.appspot.com" "ip.telize.com" "curlmyip.com" "ifconfig.me" ) +for h in ${Hosts[@]} +do + myip=$(curl -s $h) + if isIP $myip + then + echo "External IP is : $myip" + exit 0 + fi +done + diff --git a/healthReport.sh b/healthReport.sh index 9e3f939..0dd5ba6 100755 --- a/healthReport.sh +++ b/healthReport.sh @@ -16,8 +16,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -sendername="Tetras Libre" -recipient="$sendername <admin@tetras-libre.fr>" +sendername="root@`hostname`" +recipient="root" level=info date="$(date +%y%m%d_%H%M)" archiveFile="HealthReport-$date.tar.xz" -- GitLab