06.03.2022, 13:14
(13.11.2019, 07:58)Joep Wrote:(13.11.2019, 05:02)josemabera Wrote: Good morning Joep
In the script the command to send this information by e-mail would be missing, right?
How can I send this information by e-mail every day at night as you comment? (only one e-mail per day, or every week)
Thank you very much for sharing your knowledge in the forum
Br Josema
Hi Josema,
Below the complete script to get all the information, write it to the log and send it by email using the default email function.
You can use this script as a scheduled script and run it every x days or once a week.
What you need to do is to set the correct receiver email address in the last line of the script and if you want you can change the Dutch words to your own language.
Code:--status van de homeLYnk ophalen, loggen en mailen
require('json')
require('socket.http')
ip = io.readproc('if-json')
ip = json.decode(ip)
log("IP adres: " ..ip.eth0.inetaddr)
socket.http.timeout = 5
data = socket.http.request('http://ip-api.com/json')
if data then
data = json.decode(data)
log("WAN IP: "..data.query)
log("Plaats: "..data.city)
log("Provincie: "..data.region)
log("Land: "..data.countryCode)
log("Latitude: "..data.lat)
log("Longitude: "..data.lon)
else
log("Er is mogelijk geen internetverbinding actief")
end
log("Naam: " ..socket.dns.gethostname())
io.input("/sys/class/net/eth0/carrier")
carrier = io.read("*line")
if carrier == "1" then
log("Verbonden met het netwerk")
else
log("Geen verbinding met het netwerk")
end
io.input("/sys/class/net/eth0/operstate")
state = io.read("*line")
if state == "up" then
log("De netwerkverbinding is actief")
else
log("De netwerkverbinding is inactief")
end
log("Directe link pc/tablet visualisering: http://"..socket.dns.gethostname()..".local/scada-vis")
log("Directe link smartphone visualisering: http://"..socket.dns.gethostname()..".local/scada-vis/touch")
log("Interne link pc/tablet visualisering: http://"..ip.eth0.inetaddr.."/scada-vis")
log("Interne link smartphone visualisering: http://"..ip.eth0.inetaddr.."/scada-vis/touch")
log("Externe link pc/tablet visualisering: http://"..data.query.."/scada-vis")
log("Externe link smartphone visualisering: http://"..data.query.."/scada-vis/touch")
subject = "homeLYnk status: "..socket.dns.gethostname().." "..data.city
message = "Statusinformatie".."\r\n\r\n"..
"IP adres: " ..ip.eth0.inetaddr.."\r\n"..
"WAN IP: "..data.query.."\r\n"..
"Plaats: "..data.city.."\r\n"..
"Provincie: "..data.region.."\r\n"..
"Land: "..data.countryCode.."\r\n"..
"Latitude: "..data.lat.."\r\n"..
"Longitude: "..data.lon.."\r\n"..
"Naam: " ..socket.dns.gethostname().."\r\n\r\n"..
"Directe link pc/tablet visualisering: http://"..socket.dns.gethostname()..".local/scada-vis".."\r\n"..
"Directe link smartphone visualisering: http://"..socket.dns.gethostname()..".local/scada-vis/touch".."\r\n\r\n"..
"Interne link pc/tablet visualisering: http://"..ip.eth0.inetaddr.."/scada-vis".."\r\n"..
"Interne link smartphone visualisering: http://"..ip.eth0.inetaddr.."/scada-vis/touch".."\r\n\r\n"..
"Externe link pc/tablet visualisering: http://"..data.query.."/scada-vis".."\r\n"..
"Externe link smartphone visualisering: http://"..data.query.."/scada-vis/touch"
mail('your@email.com', subject, message)
I was trying to use this script, this script is working, i see the results by log, but i got a error on line 65 'mail('your@email.com', subject, message)'
I know it is 'mail' but i dont know how to fix this.
What script do i need to use it and do i put it on user.libraries?