Cronjob Interview Questions

1) How to execute a Linux cron job every second using Crontab?

Answer: You cannot schedule a every-second cronjob. In cron, the minimum unit you can specify is minute. In a typical scenario, there is no reason for most of us to run any job every second in the system.

2) How to execute a Linux command after every reboot using cron?

Answer: Using the @reboot cron keyword. This will execute the specified command once after the machine got booted every time. @reboot [COMMAND]

3) How to deny particular user using from scheduling cron jobs?

Answer: Make entry of user in /etc/cron.deny file. This way user will not be able to schedule/edit cron jobs.

4) What is the name of the service associated with cron jobs?

Answer: crond

5) If I make an entry of a user in /etc/cron.deny then will I have to restart the crond service in order to make it effective?

Answer: No. There is no need to restart crond service.

6) What will happen if we delete /etc/cron.deny and /cron.allow files?

Answer: Only root user will be able to schedule cron jobs.

7) If there are few crons configured for a particular user and its password gets expired, will the cron jobs continue to run?

Answer: No. The cron jobs will stop running.

Answer: In the file /var/log/cron.

9) What is the best way if I want only some users to have privileges to schedule crons?

Answer: Delete /etc/cron.deny file and create a /etc/cron.allow file. Make entry of users in /etc/cron.allow. Thus, only those users will be able to schedule crons. All other users will not be able to schedule crons.

10) Is it necessary to restart crond service after editing crontab for any user?

Answer: No.

11) If there are some crons configured for a user which are running fine, the root user put that particular user in /etc/cron.deny list. Will the crons already configured for the user continue to run?

Answer: Yes, crons will continue to run but the user will not be able to edit, view or remove its crontab entries.