sh範例檔案:
#!/bin/bash
if [ "$USER" == "root" ];then
echo "about 10 minutes from rotating log."
nowtime="`date '+%Y%m%d%H%M'`"
af=access_log."$nowtime"
ef=error_log."$nowtime"
cd /application/apache/logs
mv access_log "$af"
mv error_log "$ef"
/application/apache/bin/apachectl graceful<
#置換時間不固定,等待10分鐘後繼續後續備存動作
sleep 600
gzip -9 "$af" "$ef"
chown phper:users "$af".gz
chown phper:users "$ef".gz
chown phper:users access_log
chown phper:users error_log
else
echo "Please switch the user to \"root\"."
fi
備存結果: