一半君的总结纸

听话只听一半君

at用法收藏 – linux 下的计划任务

抄袭自此 和cron的主要不同是,临时用用,只运行一次就用at,想灵活些/多次运行/周期性运行就用cron
at : execute commands at specified time.
atq : lists the pending jobs of users.
atrm : delete jobs by their job number.

1. Schedule first job using at command

Below example will schedule “ls -l” command to be executed on next 9:00 AM once.

# at 9:00 AM
at> ls -l
at> ^d
job 3 at 2013-03-23 09:00

Use ^d to exit from at prompt.

2. List the scheduled jobs using atq

When we list jobs by root account using atq , it shows all users jobs in result. But if we execute it from non root account, it will show only that users jobs.

# atq
3       2013-03-23 09:00 a root
5       2013-03-23 10:00 a rahul
1       2013-03-23 12:00 a root

Fileds description:
First filed: job id
Second filed: Job execution date
third filed: Job exectuion time
Last fileld: User name, under which job is scheduled.

3. Remove scheduled job using atrm

You can remove any at job using atrm using there job id.

# atrm 3
# atq
5       2013-03-23 10:00 a rahul
1       2013-03-23 12:00 a root

4. Check the content of scheduled at job

atq command only shows the list of jobs but if you want to check what script/commands are scheduled with that task, below example will helps you.

# at -c 5

In above example 5 is the job id.

Examples of at Command:

Example 1: Schedule task at comming 10:00 AM.
# at 10:00 AM

Example 2: Schedule task at 10:00 AM on comming Sunday.
# at 10:00 AM Sun

Example 3: Schedule task at 10:00 AM on comming 25′th July.
# at 10:00 AM July 25

Example 4: Schedule task at 10:00 AM on comming 22′nd June 2015.
# at 10:00 AM 6/22/2015
# at 10:00 AM 6.22.2015

Example 5: Schedule task at 10:00 AM on same date at next month.
# at 10:00 AM next month

Example 6: Schedule task at 10:00 AM tomorrow.
# at 10:00 AM tomorrow

Example 7: Schedule task at 10:00 AM tomorrow.
# at 10:00 AM tomorrow

Example 8: Schedule task to execute just after 1 hour.
# at now + 1 hour

Example 9: Schedule task to execute just after 30 minutes.
# at now + 30 minutes

Example 10: Schedule task to execute just after 1 and 2 weeks.
# at now + 1 week
# at now + 2 weeks

Example 11: Schedule task to execute just after 1 and 2 years.
# at now + 1 year
# at now + 2 years

Example 12: Schedule task to execute at mid night.
# at midnight

Above job will execute on next 12:00 AM

Thanks for reading this article, I hope you will understand to how to use ‘at’ command in Linux.

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: