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.



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

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”
echo "End backup normally, shutting down BACKUP NAS "
ssh -p 32022 admin@ sudo "poweroff"

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.


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.








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.

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...