定时自动部署和更新hexo
#!/bin/bashfunction startServer(){cd /opt/blognohup hexo server -p 80 >/dev/null 2>&1 &echo "start server sucess !!! PID ::: "getPID}function stopServer(){ps -ef|grep hexo |grep -v grep | grep -v cron |grep -v blog | grep -v /bin/bash | grep -v /bin/sh | awk '{print $2}' | xargs kill -9 >> /dev/nullecho "stop hexo success !!! "}function getPID(){ps -ef | grep hexo | grep -v grep | grep -v cron | grep -v blog | grep -v /bin/bash | grep -v /bin/sh | awk '{print $2}'echo ""}function autoUpdate(){chkHexo=`ps -ef|grep hexo | grep -v cron | grep -v grep |grep -v blog | grep -v /bin/sh | grep -v /bin/bash |awk '{print $2}'`if [[ -z $chkHexo ]];thenecho "hexo server is stop !!! "elsestopServerfikillall nginxecho ""cd /opt/blogrm -rf db.jsonhexo cleanhexo generategulpnginx}function autoDeploy(){autoUpdatecd /opt/blogset timeout 200000/usr/bin/expect <<-EOFspawn hexo deployexpect "Username"send "$gitUn\r"expect "Password"send "$gitPwd\r"interactexpect eofEOFstartServer}. /etc/profileautoDeployecho ""echo -n "-------------- auto deploy "echo `date +"%F %H:%M:%S"`echo ""echo ""
配置定时任务
[root@hostname ~]crontab -e添加如下一行:30 23 * * * root `sh /opt/blog/hexo-deploy.sh >> /tmp/test.txt`
