#!/bin/bash function sync_library { echo "stop calibre service: 'service calibre-server stop' " /usr/sbin/service calibre-server stop #echo "wait for 1 sec to make sure calibre stopped" #sleep 1 #echo "force kill calibre server" #pkill -15 -u www-data -f "/opt/calibre/bin/calibre-server" echo "sync book data to lawipac.com/var/www/MyBooks" rsync -ah --delete /var/www/nextcloud/data/patrick/files/MyBooks/ /var/www/MyBooks/ echo "make sure www-data owns /var/www/MyBooks" chown www-data:www-data -R /var/www/MyBooks echo "check md5sum of metadb" CLOUD=`md5sum /var/www/nextcloud/data/patrick/files/MyBooks/metadata.db | awk '{print $1}'` WWW=`md5sum /var/www/MyBooks/metadata.db | awk '{print $1}'` echo "MD5 of Metadata.db CLOUD=$CLOUD WWW=$WWW " if [ $CLOUD != $WWW ]; then echo "MD5 mismatched after Sync !! ERROR =========="; #send email to sp@lawipac.com to inform the error email_failed else echo "successfully updated book library" email_success fi echo "service calibre-server start" #systemctl daemon-reload /usr/sbin/service calibre-server start } function email_failed { /usr/sbin/ssmtp -F "书库同步出错" sp@lawipac.com < To: sp@lawipac.com MIME-Version:1.0 Content-type: text/html; charset=utf-8

经过同步之后的 MD5 不匹配 !!!;

云:`md5sum /var/www/nextcloud/data/patrick/files/MyBooks/metadata.db`

书库:`md5sum /var/www/MyBooks/metadata.db`

Please do not reply this email Kind Regards < /br> lawipac
`date`
EOF } function email_success { BOOK_LIST=`calibredb list -s "date:>=1daysago" -ftitle --with-library=/var/www/MyBooks` #use cat to test locally #cat << EOF #send email using ssmtp /usr/sbin/ssmtp sp@lawipac.com << EOF Subject: 新书通知:Calibre Books updated From: 成长书库 To: sp@lawipac.com MIME-Version:1.0 Content-type: text/html; charset=utf-8

最近(昨天,今天)新增图书: