{"id":713,"date":"2015-11-01T20:12:26","date_gmt":"2015-11-01T19:12:26","guid":{"rendered":"http:\/\/pinguino.walii.es\/?p=713"},"modified":"2020-07-02T11:19:32","modified_gmt":"2020-07-02T10:19:32","slug":"email-script-from-bash","status":"publish","type":"post","link":"https:\/\/pinguino.walii.es\/?p=713","title":{"rendered":"Email from BASH script"},"content":{"rendered":"

I did looking for a solution to inform to me when a distributed router is reseted\/rebooted, and add to it some information, like public IP, GEO position and hostname of the router.<\/p>\n

And I found this solution, a script into the boot order that send to me a email with this information.<\/p>\n

<\/code><\/p>\n

root@rasp3:\/home\/pi# cat sendMail.sh
\n#!\/bin\/bash
\nmyPublicIP=$(wget -q -O - checkip.dyndns.org|sed -e 's\/.*Current IP Address: \/\/' -e 's\/<.*$\/\/')
\necho $myPublicIP
\nmyGPSposition=$(geoiplookup $myPublicIP)
\necho $myGPSposition
\nquienSoy=$(whoami)
\necho $quienSoy
\nlocalHost=$(hostname)
\necho $localHost
\ndt=`date '+%d\/%m\/%Y_%H:%M:%S'`
\necho $dt
\nrun=$(mail -s \"Server $localHost rebooted\" iphone@walii.es <<< \"El router $localHost se ha conectado desde:\\n IP: $myPublicIP \\n Posicion GPS: $myGPSposition \\n Fecha $dt\")<\/p>\n

 <\/p>\n

<\/code><\/code><\/p>\n

and the next code into the init folder.<\/p>\n

<\/code><\/p>\n

\/etc\/init.d\/sendMailRun<\/p>\n

case \"$1\" in
\nstart)
\necho -n \"SEND MAIL\"
\n\/home\/pi\/SCRIPTS\/sendMail.sh & >\/dev\/null
\necho \".\"
\n;;
\nstop)
\necho -n \"SEND MAIL NO NEEDED\"
\necho \".\"
\n;;
\nrestart)
\necho -n \"SEND MAIL AGAIN\"
\n\/home\/pi\/SCRIPTS\/sendMail.sh & >\/dev\/null
\necho \".\"
\n;;
\n*)
\necho \"Usage: \/etc\/init.d\/radius {start|stop|re-send}\"
\nexit 1
\nesac<\/p>\n

exit 0<\/p>\n

 <\/p>\n

<\/code><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"

I did looking for a solution to inform to me when a distributed router is reseted\/rebooted, and add to it some information, like public IP,…<\/p>\n","protected":false},"author":2,"featured_media":798,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[44,43],"tags":[],"_links":{"self":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts\/713"}],"collection":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=713"}],"version-history":[{"count":6,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts\/713\/revisions"}],"predecessor-version":[{"id":799,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/posts\/713\/revisions\/799"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=\/wp\/v2\/media\/798"}],"wp:attachment":[{"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pinguino.walii.es\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}