Linux hint no crontab for root solution

Source: Internet
Author: User
Tags cron script

Linux hint no crontab for root solution
Uploaded by: yuyan3081
I also want to " share the Money"
2014/6/19
attention ( 2004)
Comments ( 0)

• The registration will send 50 Yuan: Wen Shang loan-the first listed P2P registered in the country to send 110 yuan, investment to send Mercedes-Benz Smart

Good friend, there is a good gift: million Yuan red envelopes waiting for you! • Huitong Easy loan: 10 seconds registration, million red envelopes Duang smashed!

Synchronize your data today. To prepare for data synchronization, you first create a synchronization automation job. After entering the system, it is found that there is no crontab. So create one and follow these steps:

1. Log in to the root user.

2. Enter under root: crontab-e

3, you may be prompted:

No crontab for root-using an empty one

Then you will be called "Select a editor ..." and there are a few options for you to choose the editor. (Choose Vim.tiny)

Or go directly to the edit page.

4, enter crontab edit page after the direct "shift+:", then enter Wq save can. Then a new crontab is created!

===========================================================================

 How to perform tasks regularly under Linux crontab usage notesCategory: Linux AIX2012-11-08 10:22 4831 people read reviews (0) favorite reports How to perform tasks regularly under Linux "not original, personal online collection organized a bit"

In Linux, the tasks performed by the cycle are typically handled by the cron Daemon (ps-ef|grep cron). Cron reads one or more configuration files that contain the command line and its invocation time.
The cron configuration file is called "crontab" and is shorthand for "cron table".

First, cron find the configuration file in 3 places:
1,/var/spool/cron/This directory is stored in each user including root crontab task, each task is named after the creator, such as Tom built crontab task corresponding to the file is/var/spool/cron/tom.
Generally, a user has only one crontab file at most.

/etc/crontab This document is responsible for arranging the crontab of maintenance systems and other tasks developed by the system administrator.
Shell=/bin/bash
Path=/sbin:/bin:/usr/sbin:/usr/bin
Mailto=root
home=/
#.----------------Minute (0-59)
# | .-------------Hour (0-23)
# |  | .----------Day of Month (1-31)
# |  |  | .-------month (1-12) OR jan,feb,mar,apr ...
# |  |  |  | .----Day of Week (0-6) (sunday=0 or 7) or
#sun, Mon,tue,wed,thu,fri,sat
# |  |  |  | |
# * * * * * command to be executed

/etc/cron.d/This directory is used to store any crontab files or scripts to be executed.


Iv. Permissions
Crontab permissions issue to/var/adm/cron/next look, file Cron.allow and Cron.deny exist
Use the following:
1. If none of the two files exist, only the root user can use the crontab command.
2, if the Cron.allow exists but Cron.deny does not exist, only the users listed in the Cron.allow file can use the crontab command, if the root user is not inside, then the root user can not use crontab.
3, if the Cron.allow does not exist, Cron.deny exist, only the users listed in the Cron.deny file can not use the crontab command, other users can use.
4, if two files exist, then listed in the Cron.allow file and not listed in Cron.deny users can use crontab, if two files have the same user,
If the user is in the Cron.allow file, you can use the crontab command if there is a user in the Cron.allow.


Normal users in AIX have crontab permissions by default, and if you want to restrict users from using crontab, you need to edit/var/adm/cron/cron.deny
Hp-unix in the default normal user does not have crontab permissions, to release the normal user's crontab permissions can be compiled

V. Create a cron script
The first step: Write a cron script file named Crontest.cron.
15,30,45,59 * * * * echo "xgmtest ..." >> Xgmtest.txt, every 15 minutes, executes the print once command
Step Two: Add a scheduled task. Executes the command "Crontab Crontest.cron". Get
Step three: "Crontab-l" to see if the timed task is successful or if the corresponding cron script is generated under/var/spool/cron


Vi. Cron Services
Cron is a timed execution tool under Linux that can run a job without human intervention.
/sbin/service Crond Start//Startup service
/sbin/service Crond stop//Shut down service
/sbin/service crond Restart//Restart service
/sbin/service Crond Reload//Reload Configuration
/sbin/service crond Status//view service statuses



Crontab usage
The crontab command is used to install, delete, or list tables used to drive a cron background process. The user places the sequence of commands that need to be executed in the crontab file for execution.
Each user can have their own crontab file. The crontab file under/var/spool/cron cannot be created directly or modified directly. The crontab file was created with the crontab command

How to enter the command and time to execute in the crontab file. Each row in the file contains six fields, the first five of which are the time the specified command was executed, and the last field is the command to be executed.
Spaces or tabs are used to separate each field. The format is as follows:
Minute hour day-of-month month-of-year day-of-week commands
Legal value 00-59 00-23 01-31 01-12 0-6 (0 is Sunday)
In addition to the numbers there are several special symbols that are "*", "/" and "-", ",", * represent all the values within the range of the number, "/" for each meaning, "/" for each of the 5 units, "-" represents from a number to a number, "," separate several discrete numbers.

-L Displays the current crontab on the standard output.
-R Deletes the current crontab file.
-e Edit the current crontab file using the editor referred to in visual or editor environment variables. When you finish editing, the edited file is automatically installed.

A few examples:
Every morning at 6.
0 6 * * echo "Good morning." >>/tmp/test.txt//Note simply Echo, no output is visible from the screen, because cron emails any output to root.

Every two hours
0 */2 * * echo "has a break now." >>/tmp/test.txt

11 o'clock to 8 a.m. every two hours and eight a.m..
0 23-7/2,8 * * * echo "a good Dream" >>/tmp/test.txt

Every month, number 4th and Monday to Sunday, three a.m., 11.
0 4 * 1-3 command line

January 1 morning, 4.
0 4 1 1 * command line Shell=/bin/bash path=/sbin:/bin:/usr/sbin:/usr/bin mailto=root//If an error occurs or there is data output, the data is sent to this account as an email home= /

Execute scripts within/etc/cron.hourly per hour
* * * * * Root run-parts/etc/cron.hourly
Execute scripts within/etc/cron.daily daily
4 * * * Root run-parts/etc/cron.daily

Execute scripts within/etc/cron.weekly every week
4 * * 0 root run-parts/etc/cron.weekly

Every month to execute scripts within the/etc/cron.monthly
4 1 * * Root run-parts/etc/cron.monthly

Note: "Run-parts" This parameter, if you remove this parameter, you can later write to run a script name, not the folder name.

Every day 4 o'clock in the afternoon, 5, 6 points of 5 min, min, min, min, min, min, when the execution of orders.
5,15,25,35,45,55 16,17,18 * * command

Every Monday, three, five 3:00 the system enters the maintenance state and restarts the system.
* * 1,3,5 shutdown-r +5

10 minutes per hour, 40 minutes execute the innd/bbslin command in the user directory:
10,40 * * * * Innd/bbslink

1 minutes per hour execute the bin/account command in the user directory:
1 * * * * bin/account

Execute two instructions (each instruction is delimited) below the user directory every day 3:20 A.M.:
3 * * * (/bin/rm-f expire.ls logins.bad;bin/expire$#@62;expire.1st)

Each year in January and April, 4th to 9th of 3:12 and 3:55 execute/bin/rm-f expire.1st This command, and add the results after mm.txt this file (mm.txt file is located in the user's own directory location).
12,55 3 4-9 1,4 */bin/rm-f expire.1st$#@62;$#@62;mm.txt







The AT command implements timed tasks
If we just want to have a specific task run once, then it's time to use the AT Monitoring program.
At similar to the print process, the task is placed in the/var/spool/at directory and run at a specified time. The AT command is the equivalent of another shell, and when the at time command is run, it sends commands that can enter arbitrary commands or programs.

The AT command execution process is as follows

# at 2:05 tomorrow

At>/home/kyle/do_job

At> Ctrl+d

The time representation method in

-----------------------------------------------------------------------

Time Example Description

-----------------------------------------------------------------------

Minute at now + 5 minutes task runs after 5 minutes

Hour at now + 1 Hour task runs after 1 hours

Day at now + 3 days task runs after 3

Weeks at now + 2 Weeks task runs after two weeks

Fixed at midnight task runs at midnight

Fixed at 10:30pm mission at night 10:30

Note: Linux defaults to not booting, while Ubuntu defaults to boot. Check whether it is started, check the syntax with service ATD, check the status of ATD with service ATD status, and start the ATD Service with Service ATD start.

Check the details of the at execution: generally located under the/var/spool/at directory, with VI open, in the last part is your execution program



Detailed parameters
-V: Print version number
-Q: Stored with the specified queue (queue), where the data is stored in so-called queue, the user can use multiple queue at the same time, and the queue is numbered A, B, C ... z and a, B, ... Z total of 52
-M: Send a letter to the user even if there is no output after the program/instruction execution is completed
-F file: Read in a pre-written command file. The user does not have to use the chat mode to enter, you can first write all the specified file after the first read into the
Web applications


-L: Lists all designations (users can also use ATQ directly without at-l)
-D: Delete specified (users can also use ATRM without at-d)
-V: Lists all completed but not yet deleted specified

Delete a task
ATRM 2


Three days later, 5 o'clock in the afternoon Chung/bin/ls:
At 5pm 3 Days/bin/ls

Three weeks later, 5 o'clock in the afternoon Chung/bin/ls:
At 5pm 2 Weeks/bin/ls

Tomorrow's 17:20 execution/bin/date:
At 17:20 Tomorrow/bin/date

The last minute of the last day of 1999 prints the end of world!
At 23:59 12/31/1999 echo the end of world!====================================================================

The cron service is a built-in service for Linux, but it does not boot automatically. You can start and stop the service with the following command:

/sbin/service Crond Start
/sbin/service Crond Stop
/sbin/service Crond Restart
/sbin/service Crond Reload

The above 1-4 lines start, stop, restart the service, and reload the configuration, respectively.

To set cron to start automatically when booting, in the/etc/rc.d/rc.local script can be added /sbin/service crond start

View current user's crontab, enter crontab-l;

Edit Crontab, enter crontab-e;

Delete crontab, enter Crontab-r

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux hint no crontab for root solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.