Professional Documents
Culture Documents
Cron (aka Crontab) is a task scheduler in Linux that helps to execute a task on a scheduled time, and it is very
similar to Windows Task Schedulers.
With crontab, we can schedule repetitive tasks as well as one-time tasks using @ utility.
Crontab is mostly used for executing backup scripts for taking the system backups and also sometimes to start and
stop applications.
Crontab
Install Crontab
The package name of crontab in CentOS / RHEL is cronie and cron in Ubuntu / Debian. You can install
crontab using the below command.
Start Crontab
If the crontab is not running, then start it using the following command.
Edit crontab
To add or edit crontab jobs of a current logged in user, use the below command. The command will open a file
editor where you can update the jobs.
crontab -e
To edit other users crontab jobs, use the below command.
crontab -e -u raj
Crontab path
System wide crontab entries are found in /etc/cron{tab,.d,.daily,.hourly,.monthly,.weekly} and individual
users crontab jobs are found in /var/spool/cron/ directory.
Crontab logs
Crontab logs can be found in /var/log/cron
0 1 * * * /path/to/script.sh
This job runs every day 1 AM.
0 10,22 * * * /path/to/script.sh
Above cron runs twice a day at 10 AM and 10 PM.
0 1 * * sun /path/to/script.sh
OR
0 1 * * 0 /path/to/script.sh
OR
0 1 * * 7 /path/to/script.sh
0 or 7 means Sunday.
* * * * * /path/to/script.sh
*/5 * * * * /path/to/script.sh
0 * * * * /path/to/script.sh
OR
@hourly /path/to/script.sh
0 */2 * * * /path/to/script.sh
0 0 * * * /path/to/script.sh
OR
@daily /path/to/script.sh
0 0 */2 * * /path/to/script.sh
0 13 * * tue,thu /path/to/script.sh
@weekly /path/to/script.sh
This cron runs every week Sunday at 12 AM.
0 11 15 * * /path/to/script.sh
@monthly /path/to/script.sh
0 0 * jan,apr,jun * /path/to/script.sh
@reboot /path/to/script.sh
MAILTO="raj"
1 1 * * * /path/to/script.sh
SHELL=/bin/sh
1 1 * * * /path/to/script.sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
1 1 * * * /path/to/script.sh
19. Set Home for cron
Do you want to set the home directory to use when executing scripts? Then use this.
HOME=/
1 1 * * * /path/to/script.sh
That’s All. You can also read cron manual for more information.
29
5122
Before installing the VNC server, let us install Gnome desktop using YUM command.
cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:5.service
Edit the copied file.
vi /etc/systemd/system/vncserver@:5.service
At the end of the file, you will find the lines like below.
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l <USER> -c "/usr/bin/vncserver %i"
PIDFile=/home/<USER>/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
Replace <USER> with your real user, in my case, i replaced with a user called “raj” .
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
# Clean any existing files in /tmp/.X11-unix environment
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/sbin/runuser -l raj -c "/usr/bin/vncserver %i"
PIDFile=/home/raj/.vnc/%H%i.pid
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
Add firewall rules to allow the VNC connection, the following rule is set as per the port-offset mentioned in the
previous step.
Password:
Verify:
xauth: file /home/raj/.Xauthority does not exist
systemctl daemon-reload
Start the VNC service as root.
ipaddress:5905 or ipaddress:5
Configure VNC Server on CentOS 7 – VNC
Connection
You will be asked to enter the password, enter the password that you have created earlier.