Jump to content
XPEnology Community

How to shut down remote server using Synology SQLITE3 and Log Center advanced function (Shell Script)


Peter Suh

Recommended Posts

 

SQLITE3 is already built into Synology.
And, in order to use this function, you need to install the advanced log center function in the package manager once more to set up the log center archive.

 

This is an example of sending a remote shutdown command after completing shared folder synchronization.

 

Saves the results of the successful processing of shared folder synchronization to a DB file through the Log Center.

And then we're going to use SQLITE3 built-in synology to re-Script to check.


Once a normal BACKUP has been verified, the remote NAS server can be shut down via the SSH command.


The method is to create a storage destination for archiving settings in Log Center to storage destinations for archive

Select the appropriate folder (in my case, /volume2/log , It could also be /volume1/log ) to download log db files.

Archives local logs to the storage location specified above [V]. Check the and apply it.

 

1623471587_JoNCL.thumb.png.1455fdb6775183bdf068fedc7c296509.png


This DB file is for SQL LITE, running sqlite3 shown in the command below, and opening the DB file specified above as an archive.

And you can know the result with a query that SELECT count the successful processing of normal synchronization today.



If the value 1 is printed on the r variable, it means that the normal performance is completed, and the backup is only done once a day.

If you have more backups, you should modify the queries and IF conditions in the script below.

In the synology, create a shell script in the shell folder using the vi editor as shown below.
 

vi /volume2/shell/poweroff_af_backup.sh


#!/bin/bash
r=$(sqlite3 /volume2/log/SYNOSYSLOGDB__LOCALARCH.DB "select count(*) as cnt from logs a where host = ‘MAIN NAS' and ldate = date('now','localtime') and prog = 'NetworkBackup' and instr(msg,'Shared Folder Sync finished to sync task') > 0;")
echo $r
if [ $r -eq "0" ] ; then
echo “Shared folder sync error or Not Complete”
else
echo "End backup normally, shutting down BACKUP NAS "
ssh -p 32022 admin@192.168.35.11 sudo "poweroff"
fi




To automatically shut down the remote server with Wish, a copy of the pub key generation via ssh-keygen is required. For this part, please refer to the link below.

https://www.synoforum.com/threads/how-to-log-in-without-ssh-password-how-to-log-in-without-password.6111/


The completed script can be registered with the work schedule, given the appropriate frequency, and checked continuously so that the remote server can be shut down if the backup succeeds.

 

2131374385_2022-10-148_52_22.thumb.png.12126fba1980258b484afa8c133a4ab8.png

 

308101007_2022-10-148_52_29.thumb.png.ac63b036ddd825aa38e20c207d798ee2.png

 

745754313_2022-10-148_52_45.thumb.png.d294d559672928200b55c2da5aab98a2.png

 


Thank you.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...