"Shell" uses/dev/null crontab

Source: Internet
Author: User
Tags ssh account

1.Linux composition kernel, shell, tool program has Sh.bash

An example

!#/bin/bash

Echo '

Before execution chmod +x

Execution./

2. a little trick cp/dev/null/var/log/apache2/access.log

Use/dev/null to apache2 log files in the clear sky

Note: Think of /dev/null as a "black hole". It is very equivalent to a write-only file. All content written to it is lost forever. and trying to read from it is nothing. However, /dev/null Very useful for both command lines and scripts.

Prohibit standard output .

   1 cat $filename >/dev/null   2 # file content is lost without output to standard output.

Prohibit standard error (from Example 12-3).

   1 rm $badname 2>/dev/null   2 #           this error message [standard error] was thrown into the Pacific Ocean.

Suppresses output of standard output and standard error.

   1 cat $filename 2>/dev/null >/dev/null   2 # if "$filename" does not exist, no error message will be prompted.   3 # if "$filename" exists, the contents of the file will not be printed to standard output.   4 # So therefore, the above code will not output any information at all.   5 #   6 #  useful when you want to test the exit code of a command without any output.   7 #   8 #   9 # cat $filename &>/dev/null  #     can also be noted by Baris Cicek.

Example 28-1. Hide cookies and no longer use them

   1 if [-F ~/.netscape/cookies]  # is deleted if it exists.   2 then   3  rm-f ~/.netscape/cookies   4 fi   5   6 ln-s/dev/null ~/.netscape/cookies   7 # Now all the cook IES will be thrown into a black hole and will not be saved on disk.

the meaning of 1>/dev/null 2>&1

the shell can often be seen: >/dev/null 2>&1

The result of the command can be defined in the form of a%> output

/dev/null represents an empty device file
Where does the > delegate redirect to, for example: Echo "123" >/home/123.txt
1 means stdout standard output, the system default is 1, so ">/dev/null" is equivalent to "1>/dev/null"
2 indicates stderr standard error
& means equivalent to, 2>&1, 2 output redirect equals 1

Then the statement in the title of this article:
1>/dev/null first indicates that the standard output is redirected to an empty device file, that is, not outputting any information to the terminal, which is plainly not displaying any information.
2>&1 then, the standard error output redirection is equivalent to the standard output because the standard error output is redirected to the empty device file because the standard output was previously redirected to an empty device file.

Source: http://www.yunwei.org/read.php?18

Tips IO redirection Ls>1.txt Saving results to a file

3. Using crontab to automatically clean up log files

Just write the above sh file into the crontab.

 usage rights : Root user and owner of crontab file


crontab format

Syntax: crontab [-E [Username]|-l [Username]|-r [username]|-v[username]| File] Description : crontab is used to allow the user to execute the program at a fixed or fixed interval, in other words, a user-like time table. -u user refers to the setting of the time table for the specified user, which presupposes that you must have permission (for example, root) to specify another's time schedule.   If you do not use the-u user, it means setting your own schedule. parameters :-E [UserName]: Perform a text editor to set the time table, the default text editor is VI, if you want to use a different text editor, you first set the VISUAL environment variables to specify the use of the text editor (for example, setenv visual Joe )-R [UserName]: Delete current Schedule table-l [UserName]: List Current Schedule table

-V [UserName]: Lists the status of the user cron job

Example Crontab-u root-e can open VI.

And then write 0 6 * * * * * * * * * * * * * * /root/clearlog.sh every morning 6.

0 * * * */bin/ls 0 minutes per day of every month/bin/ls

*/20 6-12 */usr/bin/backup

In December, every 20 minutes in the morning from 6 to 12./usr/bin/backup

200-23/2 * * * echo "haha"

Every day of the month 0:20 midnight, 2:20, 4:20 .... Perform echo "haha"

4, the deployment of Bashshell environment

Echo$shell See SHELL version/bin/bash

we can bash-3.2.48.tar.gz the source code from the Internet .

Unzip./configure can also be used to specify the installation directory via--PREFIX=/HOME/OLS32

Compiling make test make tests

  

5, login ssh If you do not specify an account example SSH 192.168.1.2 equivalent to log in as root

or SSH account @ip such as SSH [email protected]

"Shell" uses/dev/null crontab

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.