Shell Learning Essays

Source: Internet
Author: User
Tags crontab example

Cat/dev/null > FileName Empty file information Trash, the data sent to the secondary file will be deleted. W.H.O. | Wc-l calculating the number of users | (pipeline) can be two more programs between the establishment of a pipeline pipe:who output into the WC input. The result of the WC list is the number of users logged in.  , printf command echo output echo $? Echo $SHELL
The ptintf output does not automatically provide line breaks like Echo, and it needs to be added by itself.
Simple execution of the trace. Shell script Tracing feature, the Set-x command opens the function to perform tracing. It is then closed with the Set +X command set-x is not tracked because the trace function is not opened until this command is executed. In the same vein, set +x will be tracked, and he will not be followed.
grep find text

& in the replacement text means: Replace the entire text with the regular expression from this point.
In the S command, the end of G is marked: Global, that is, alternative text replaces each match in the regular expression. If not set g,sed will only replace the first matching
The-n parameter in sed. The-n option parameter modifies the default behavior of SED. When this option is provided, SED will not print the last contents of the pattern space after the operation is complete. Conversely, if you use p in your script, it will be displayed. 3. Match a specific line
The Cut command is used to cut down the data in the text file.

Use Join to connect fields. Delete comments and sort: awk command: pattern or action
If you want a field value, you need to match the $ character. Usually the $ followed by a numeric constant, or the next expression, but mostly with the variable name.
awk start and clear: Global variables and local variables: The global variable is temporarily in effect and will need to be added to the. profile file if it is made permanent. Local variables take effect only when the script executes. Export variable name =value; variable name =value;export variable name
(The CentOS write profile can take effect, but there is a problem with Ubuntu writing profiles.) echo does not display).

$? Exit the status variable. $? Save a command or a function or the exit status of the script itself. () command group note: The list of commands in () is run as a child shell. The variable in () is not available for the remainder of the script because it is in a child shell.
Example: a=123 (a=321) echo "a= $a" #a = 123 A variable in parentheses is more like a local variable.
The cat {file1,file2,file3} >combine_file #把文件123连接在一起 and redirects to the CP File22 in Combined_file. {txt,backup} #拷贝file22. txt to File22.backup
{} code block: Also known as an internal group, in fact, this structure creates an anonymous function, but unlike a function, the variable declared in it is visible to the code of the rest of the script. (differs from the above ())
Sort sorts not studied .....

Calculate numbers, Bytes: Display: variables, judgments, arithmetic: The export command tightly adds variables to the environment, and if you want to remove variables from the program's environment, you can also temporarily change the values of the environment variables with the ENV command. The unset command removes variables and functions from the executing shell:

Linux uses the crontab command to execute shell scripts or other Linux commands on a timed basis

With Crontab you can execute a shell script or a series of Linux commands at a specified time. For example, the system administrator schedules a backup task to run every day

How do I add a job to cron?

# crontab–e
0 5 * * */root/bin/backup.sh

This will run at 5 o '/root/bin/backup.sh every morning.

Description of Cron Items

The following is the format of the crontab file:

{minute} {Hour} {Day-of-month} {Month} {Day-of-week} {Full-path-to-shell-script}
O minute: Interval is 0–59
O Hour: Interval is 0–23
O Day-of-month: Interval is 0–31
O Month: The interval is 1–12. 1 was January. 12 was December.
O Day-of-week: Interval is 0–7. Sunday can be 0 or 7.

Crontab Example

1. Run at 12:01 a.m., which is a minute every morning. This is an appropriate time to make a backup, because the system is not loaded at this point.

1 0 * * */root/bin/backup.sh

2. The backup job is performed every weekday (MON–FRI) 11:59 p.m.

* * 1,2,3,4,5/root/bin/backup.sh

The following example has the same effect as the example above:

* * 1-5/root/bin/backup.sh

3. Run the command every 5 minutes

*/5 * * * */root/bin/check-status.sh

4.1:10 p.m. on the first day of each month

1 * */root/bin/full-backup.sh

5. Run every weekday.

0 * * 1-5/root/bin/incremental-backup.sh

Crontab Options

The following are the valid options for crontab:

o Crontab–e: Modify the crontab file. If the file does not exist, it is created automatically.
O crontab–l: Displays the crontab file.
o Crontab-r: Delete the crontab file.
O Crontab-ir: Alert users before deleting crontab files

http://blog.csdn.net/ithomer/article/details/6817019

Note: To restart the cron process after editing is complete:

~#/etc/init.d/cron Restart


Script Execution methods:
1.bash or sh+ script 2.bash or sh think execution path + script above two kinds are: the current shell will open a child shell environment, to execute shell script does not load the current environment in the 3.source+ script 4. . /+ script above two ways to execute scripts, do not create child processes, directly under the current environment Load environment variable script.
awk command: Fetches the first line of output, awk ' Print $n '

Shell Learning Essays

Related Article

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.