ENVL and crontab commands in the shell

Source: Internet
Author: User
Tags echo command

Envl

Eval will scan two times for subsequent commands, execute this command if the command is a normal command after the first scan, and if the command contains an indirect reference to the variable, the semantics of the indirect reference is guaranteed. In other words, the eval command will first scan the command line for all permutations before executing the command. As a result, the eval command applies to variables that are not able to implement their functionality once scanned.

Eval performs the following two steps

    • For the first time, perform variable substitution, similar to the C-language macro substitution
    • The second time, execute the replacement command string

Chestnuts:

1. There is a file named Test with the content "please move on!" ", define a string variable that is cat test and use the echo command to refer to the variable, print the string directly, and use eval to output the contents of the file test!

This is due to the execution of the eval command for the first scan of the variable substitution, and the second scan performed the command that the string contained in cat test.

2. Get the last parameter passed to the shell script

If we know the number of arguments passed to the shell and want to output the last parameter, you can use echo to display it directly, for example, the parameters entered in this example are 10, 11, 12 total three parameters, you can use the command: Echo $

But if we don't know a few parameters, but want to output the last parameter, you might think of using $$# ($# as the number of arguments passed to the shell script) to output the last parameter.

If you use the command: echo "\$$#" gets the result of $12 instead of the one we want.

Use the eval command to reach our expectations: eval echo "\$$#" results in 12.

Shell script content:

Execute script file:

3. Another example:

[[email protected] test]$ g= ' | ' [Email protected] test]$ eval ls $G wc-l

First step variable replaced by eval ls | Wc-l second part, execute the command result.

Attention:

    1. Eval cannot get the result of function processing
    2. Eval nesting is meaningless, and in other languages it can be performed (by eval ("code")) to perform (performing a dynamically generated code return), whereas in the shell, the eval command is simply executed as a command string, and the nesting is replaced by the command. Generation.  
Crontab

Crond is a daemon that performs periodic tasks or waits for certain events under Linux, and the system automatically starts the Crond process, and the Crond process periodically checks to see if there are tasks to be performed, and automatically executes the task if there are tasks to perform.

The crontab file contains a series of jobs and instructions sent to the cron daemon. Each user can have their own crontab file, while the operating system holds a crontab file for the entire system, which is usually stored in subdirectories under/etc or/etc, and this file can only be modified by the system administrator.

The crontab command is used to set instructions that the system periodically executes . The command reads the instruction from the standard input device and stores it in a "crontab" file for later reading and execution. The/etc/crontab file is the configuration file for the system Task Scheduler.

Parameters:

-L Displays the current crontab on the standard output.

-R Deletes the current crontab file.

-e Edit the current crontab file using the editor defined by visual or editor environment variable

Use format:
* * * * * command
Time-sharing Weekly command

The 1th column represents the minute 0~59 (denoted by * or */1 per minute)
The 2nd column represents the hour 0~23
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
5th Column Identification Number Week 0~6 (0 = Sunday)
The 6th column indicates the command to be executed

In addition to the numbers there are several special symbols that are "*", "/" and "-", ",", * represent all the values within the range of numbers. "/" stands for each meaning, "/5" means every 5 units, "-" stands for a number of discrete numbers from a certain number to a digit, ",".

Some examples of use of crontab files:

#每晚的21:30 Restart Apache30 * * */usr/local/etc/rc.d/lighttpd restart# monthly 1, 10, 22nd 4:45 Restart APACHE45 4 1,10,22 * */usr/local/et C/RC.D/LIGHTTPD restart# every Saturday, Sunday 1:10 restarts apache10 1 * * 6,0/USR/LOCAL/ETC/RC.D/LIGHTTPD restart# every 30 minutes from 18:00 to 23:00  apache0,30 18-23 * * */usr/local/etc/rc.d/lighttpd restart# every Saturday at 11:00am Restart APACHE0 * * 6/USR/LOCAL/ETC/RC.D/LIGHTTPD restart# 11 o'clock to 7 in the morning, every hour to restart apache* 23-7/1 * * */usr/local/etc/rc.d/lighttpd restart# every hour restart apache* */1 * */usr/local/ ETC/RC.D/LIGHTTPD restart# 4th per month and 11-point restart from Monday to Wednesday apache0 4 * mon-wed/usr/local/etc/rc.d/lighttpd restart# January 1 4-point Restart APACHE0 4 1 Jan */usr/local/etc/rc.d/lighttpd restart# every half hour to sync time */30 * * * */usr/sbin/ntpdate 210.72.145.44

  

ENVL and crontab commands in the shell

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.