利用crontab定时任务,设置vncserver每日重启
创建 /home/ubuntu/vncserver-day.sh文件,写入下两行。
vncserver -kill :1
vncserver
给vncserver-day.sh执行权限:
chmod +x vncserver-day.sh
测试sh vncserver-day.sh 执行是否正确。
sh /home/ubuntu/vncserver-day.sh
看到屏幕打印如下日志:
Killing Xtightvnc process ID 5049
New ‘X’ desktop is ubuntu:1
Starting applications specified in /home/ubuntu/.vnc/xstartup Log file
is /home/ubuntu/.vnc/ubuntu:1.log
在crontab -e 中添加:
0 0 * * * sh /home/ubuntu/vncserver-day.sh >> /home/ubuntu/vncserver-day-log.log 2>&1
日志会自动写入/home/ubuntu/vncserver-day-log.log文件中