How to Restart VNC Server Hourly using Crontab

Sometimes I need to restart my VNC server periodically, usually hourly. So I’m gonna need crontab. In some conditions, the killing process of VNC server may still leaves some files on the VNC folder or inside temp folder. So, before we start the VNC server again, we have to make sure that those files are deleted.

Open your cron job

crontab -e

Add these lines:

1 * * * * vncserver -kill :1 && rm -rf /root/.vnc/*.pid && rm -rf /root/.vnc/*.log && rm -rf /tmp/.X11-unix/X1 && rm -rf /tmp/.X1-lock
2 * * * * vncserver

You may need to adjust the value of this /root part. This is where the files are located. If you’re running VNC server as a different user, such as johndoe, then the files maybe located in /home/johndoe

No Responses