at:-
The at command is used for jobs that need to be run only once. at is an
interactive program and it takes in an argument, which is the time and
date that you want the job to be run. All outputs of at are sent by
email.
atq will list the job number as well as the time when the job is
scheduled to be executed. To remove a job from being executed, you type atrm
followed by the job number. Now every job has a number, and this number
can be seen from the atq command.
cron;-
cron, like at is used to run a program at a scheduled time. The
difference is that cron is designed for jobs that need to be executed more
than once.
In order to schedule commands using cron, we use the crontab command.
Let's get into it right away. Let's say you want to recieve an email
every minute with the words "Hello World" on it.
First, type: crontab -e
The -e flag lets you edit your current cron table. You probably don't
have anything in there yet, so type the following:
* * * * * /bin/echo Hello World
What does that mean you say? Well, the first five asteriks specify the
minutes, the hour, the day of month, the month, and finally, the day of
the week. Now the first field ranges from 0 to 59, the second from 0 to
23, the third from 1 to 31, the fourth from 1 to 12 (or a name such as
jan, feb, mar, etc...), and the last from 0 to 6 (or a name such as
mon, tue, wed, etc...). The field that says /bin/echo Hello World is the
command field. This is where you specify what command to run at the
specified time and date. So to run this command at 2:30pm every Monday we
would type:
30 14 * * mon /bin/echo Hello World
Additionally, crontab takes the -l flag. When run in this manner,
crontab will show you your current cron table and what's scheduled to run
and when. If you are running as the root user, you can also use the -u
flag followed by a user name to edit that user's cron table or just to
list it's contents.
Restricting scheduling
If you run a system that hosts multiple users, you might want to
discourage them from using cron or at for whatever reasons. This can be done.
To restrict people from using cron, create a file called /etc/cron.deny
and put the name of the user you want to restrict in there. To restrict
people from using at, create a file called /etc/at.deny, and put the
name of the user you want to restrict in there. Be careful about
restricting default system users like nobody.
The at command is used for jobs that need to be run only once. at is an
interactive program and it takes in an argument, which is the time and
date that you want the job to be run. All outputs of at are sent by
email.
atq will list the job number as well as the time when the job is
scheduled to be executed. To remove a job from being executed, you type atrm
followed by the job number. Now every job has a number, and this number
can be seen from the atq command.
cron;-
cron, like at is used to run a program at a scheduled time. The
difference is that cron is designed for jobs that need to be executed more
than once.
In order to schedule commands using cron, we use the crontab command.
Let's get into it right away. Let's say you want to recieve an email
every minute with the words "Hello World" on it.
First, type: crontab -e
The -e flag lets you edit your current cron table. You probably don't
have anything in there yet, so type the following:
* * * * * /bin/echo Hello World
What does that mean you say? Well, the first five asteriks specify the
minutes, the hour, the day of month, the month, and finally, the day of
the week. Now the first field ranges from 0 to 59, the second from 0 to
23, the third from 1 to 31, the fourth from 1 to 12 (or a name such as
jan, feb, mar, etc...), and the last from 0 to 6 (or a name such as
mon, tue, wed, etc...). The field that says /bin/echo Hello World is the
command field. This is where you specify what command to run at the
specified time and date. So to run this command at 2:30pm every Monday we
would type:
30 14 * * mon /bin/echo Hello World
Additionally, crontab takes the -l flag. When run in this manner,
crontab will show you your current cron table and what's scheduled to run
and when. If you are running as the root user, you can also use the -u
flag followed by a user name to edit that user's cron table or just to
list it's contents.
Restricting scheduling
If you run a system that hosts multiple users, you might want to
discourage them from using cron or at for whatever reasons. This can be done.
To restrict people from using cron, create a file called /etc/cron.deny
and put the name of the user you want to restrict in there. To restrict
people from using at, create a file called /etc/at.deny, and put the
name of the user you want to restrict in there. Be careful about
restricting default system users like nobody.
Comments