Updated setup for newbies:
Creation and Edit of the User-defined script for Shutdown
1. Download the attached file "upstest.zip".
2. Unzip it somewhere on your computer.
3. It will create a new file "upstest.sh"
4. Open "upstest.sh" in your preferred simple text editor (no MS Word), e.g. Notepad and make simple edition in row no. 32:
Bash:
if [ $BATINT -le 20 ] && [ $STATUS = 'OB' ];
- there is the number
'20' in the code
- it is variably defined value in % of your UPS battery status for the NAS shutdown threshold ... then value 20 means 20% of the battery remains
- you can change the value to whatever value, up to you. 30 = 30%; 25 = 25%
- when the UPS battery will reach this value (%) and NUT upsmon (monitor) will get this information from NUT upsc (status) it will automatically run $SHTD, in this case, SHUTDOWN of the NAS.
Save the file.
Deployment of the "upstest.sh" file to the NAS
1. Use putty or something quite better for 'ssh' into your NAS - in my case I like more the
MobaXterm
2. Create a session (plenty of guides here or on the Internet, YT). You need: IP address of the NAS, admin usr/psw.
4. Use 'sudo -i' to get root session
5. In the MobaXterm terminal you can find in the left upper part (arrow) menu for upload a file. But you need to open a working directory first. So open 'opt' directory (this will be not overwritten after NAS upgrade)
click there
when opened, use UPLOAD ICON and upload the file
"upstest.sh" into your working directory:
You can use REFRESH green icon (right next to).
So, when everything is OK, then you will see the file
"upstest.sh" within 'opt' directory.
6. in the terminal window type:
to allow executable permissions for the file.
Done. Exit the terminal
Define cyclic check of the battery status in DSM
In DSM Control panel / Task Scheduler:
Create / Scheduled task / User-defined script
General tab:
Task: name of the Task ----up to you
User: root
Enabled
Schedule tab:
use these values from screenshot
Task settings tab:
Run command/User-defined script type (use the chosen path to the script):
Done. Use OK, then just check if the Task is ENABLED, select it and use RUN:
Now you can open a beer or two and call me to celebrate this task!
With this small script you will get:
Controlled Shutdown of your NAS based on EXACT battery level, e.g. 20%.
Performed only when is the UPS on Battery (no one wants shutdown of charged UPS)
Last recommendation:
- when something is wrong or just for a check, you can find ERROR LOG within:
- right click, then 'Open with Default Text Editor'
- then Ctrl+F upstest.sh to find related error