TIPS & TRICKS
To search the contents of the man pages
# man -k searchterm |
Cron job tasks
To keep in mind:
# systemctl status crond.service |
Fin the full path by using the which
command and use it in the crontab:
# which <cmd> |
Exemple:
# which echo |
Files to check:
# cat /var/log/cron // it shows list of cronjobs |
Cron job 1
| Set a Cron job that execute the script /backup.sh
every days at midnight.
Of course you need to put x right on the script.
Set the cron:
# crontab -e |
Cron job 2
| Set a Cron job for harry on 12.30 at noon print /bin/echo on “hello”.
| Create a crontab for a new user natasha that runs at 14:23 everyday and executes echo “hello”.
Set the cron (-e) for user (-u) harry:
# crontab -e -u harry |
Verify:
# crontab -l -u harry |
Set the cron (-e) for user (-u) natasha:
# crontab -e -u natasha |
Verify:
crontab -l -u natasha |
Cron job 3
| Configure a cron job that runs every 2 minutes and executes the following command:
| - logger “EX200 in progress” at the user natasha
Set the cron (-e) for user (-u) harry:
# crontab -e -u natasha |
Verify:
# crontab -l -u Krish |
Check if log message are being loggged in /var/log/messages:
# grep EX200 /var/log/messages |
Cron job 4
| Create a Daily Cron Job at 4:27pm for the derek
| User that Runs cat /etc/redhat-release
and Redirects the Output to /home/derek/release.txt
Normaly, you dont’t have to create the file /home/derek/release.txt
and configure chmod
, chown
and chgroup
.
Set the cron (-e) for user (-u) derek:
# crontab -e -u derek |
Verify:
crontab -l -u derek |
Cron job 6
| Create a periodic job that appends the current date to the file ~/tracking every 5 minutes every Sunday and Wednesday between the hours of 3am and 4am.
| Remove the ability of bob to create cron jobs
Set the cron:
# crontab -e |
If the file doesn’t exist:
# touch ~/tracking |
Remove the ability of bob to create cron jobs (just put the user to deny in it):
# echo "bob" >> /etc/cron.deny |
Cron job 7
| Create a cron job running as root, starting at 11PM every day and writing a report on daily system resource consumption in the /var/log/consumption.log file.
Command use to gather system statistics is called sysstat and may not be installed on the system. So first what we have to do is install it and then enable the service:
# yum install sysstat |
Edit crontab:
# crontab -e |
As usual it is wise to check what we have already in the system. To see crontab we just issue:
crontab -l |
Additional comment:
The log file does not need to exist - it will be created automatically.
Of course root user can edit crontab of every user with flag -u specifying user name.
It is worth remembering that there are /etc/cron.allow and /etc/cron.deny
Documentations
Internet
Git
ChatGPT