I have a server (running LMDE) and a laptop (EndeavourOS). Now the server is a file server and also every minute checks for power outage.
If I am home, I know if my power is out, but if I am not, I don’t, so I want the server to let my laptop know the power is out (and also let my PC know, but I assume the same solution can be used)
Right now, my solution goes like this:
if the server detects an outage, it creates a file in a directory the laptop has access to
laptop checks every minute for that file
if it is there, it notifies me
But that feels bloated and hacky, so is there a better way?
EMAIL="your@emailaddress"
EMAILMESSAGE="/tmp/body.txt"
echo "To: ${EMAIL}" >>${EMAILMESSAGE}
echo "From: root@your-fileserver" >>${EMAILMESSAGE}
echo "Subject: ${SUBJECT}" >>${EMAILMESSAGE}
echo "Importance: High" >>${EMAILMESSAGE}
echo "X-Priority: 1" >>${EMAILMESSAGE}
echo >>${EMAILMESSAGE}
echo "This is the text in the email" >>${EMAILMESSAGE}
sendmail -t <${EMAILMESSAGE}
rm ${EMAILMESSAGE}
PS
if you use a cronjob to check the powerstatus you can make use of the cron email feature. If cron executes a script it captures every “echo” and sends it via email to the root account of that server. Now you only need an alias in /etc/aliases or /etc/postfix/aliases, depending which OS and which MTA you use, and the email is automatically forwarded from root to that alias.
e.g. for the aliases on my debian server
# cat /etc/aliases
# See man 5 aliases for format
postmaster: root
root: my@personal.email.address
No. I also have a PC (other than the server), and sometimes I run a job on it and leave it alone. And if the power is out, it should shut down before the UPS runs out of battery power.
Call to PowerOff failed: Access denied as the requested operation requires interactive authentication. However, interactive authentication has not been enabled by the calling program.
Depending on the make and model of your UPS, there are some Network UPS Tools available that might be an easier approach to achieve the desired functionality, including network monitoring. And automatic (safe) shutdown, depending on the state of charge of the UPS itself. Therefore, I’ld recommend to approach this from the angle of the actual make and model of the UPS.
Yeah, nut server is the solution here. Place it on your server, and let it do its stuff. Beat combines with a small ups solution. But you need to have some network working without power. For that I use an UPS which powers my router, my main switch and my raspi with nut.