Linux logs and screen tools __linux

Source: Internet
Author: User

10.34-10.35 System Log and screen

The log records the various things that happen to the system every day, and you can check the log to see why the error occurred. Or the traces that were left when they were attacked.

/var/log/messages is the core system log that contains the startup messages and other state of the system runtime, as well as the log of the software that the user installs. Typically,/var/log/messages is the first file to view when a system fails.

/var/log/messages is rsyslogd This daemon started, the daemon's configuration file is/etc/rsyslogd.conf, this file defines the level of the log.

dmesg This command displays the system's startup information, starts at power-on, and is stored in memory. If there is a problem with a hardware, you can see it here.

last used to view system information for logging on to Linux.

The last command actually reads the/var/log/wtmp file, but the file cannot be viewed directly with Cat,vi,vim,head,tail.

[root@cent02 tmp]# last|tail
root     pts/1        192.168.30.1 Tue     Oct 09:30-09:49  (00:18)    
root     pts/0        192.168.30.1     Mon Oct 23:37-down   (10:46)    
root     tty1                          Mon Oct 23 22:07-10:23< c13/> (12:16)    
reboot   system boot  3.10.0-514.el7.x Mon Oct 22:06-10:23  (12:17)    
root     Tty1                          Tue Oct 05:36-crash  ( -7:-29)   
reboot   system Boot  3.10.0-514.el7.x Tue Oct 24 05:35-10:  04:48    
root     tty1                          Tue Oct 05:28-crash  (00:07)    
reboot   system boot  3.10.0-514.el7.x Tue Oct 05:27-10:23  (04:56)    

/var/log/secure records are also related to login information, such as SSH login failure information can be recorded here.

Many error messages are not reflected on the screen, but written in the log, so use the common software should also have the habit of viewing the log. such as apache,myslq,php and so on. Xargs and Exec

Xagrs can take the previous output as a later input, so you can take two steps to complete the task one step to complete. He often uses it with the Find command.

Find. -mtime +10 |xargs rm//delete files with last modification time greater than 10 days

//Following batch modification suffix name
[root@cent01 test]# ls 
1.txt  2.txt  3.txt  4.txt  5.txt
[root@cent01 test]# ls *.txt|xargs-n1-i{} mv {} {}_bak//xargs-n1-i{} is similar to a for loop,-n1 means to process the object one by one,-i{} to replace the previous object with {} , mv{} {}_bak is equivalent to MV 1.txt 1.txt_bak
[root@cent01 test]# ls 1.txt_bak 2.txt_bak 3.txt_bak  4.txt _bak  5.txt_bak

can also be used in conjunction with-EXEC.

Find. -mtime +10-exec rm-rf {} \;  The {} here also represents replacing the previous object with {}


[root@cent01 test]# find./*_bak-exec mv {} {}_bak \;//-exec with; So you need to add the escape character \, while the escape character and preceded by a space.
[root@cent01 test]# ls
1.txt_bak_bak  2.txt_bak_bak  3.txt_bak_bak  4.txt_bak_bak  5.txt_bak_bak
Screen

Sometimes a task to perform a few hours, or a few days, if the halfway break the network or unexpected situation how to do? We can solve them in two ways.

Nohup
such as executing a script

Nohup sh/uer/local/sbin/sleep.sh &//Although the end of the direct plus & can also run in the background, but if you exit the terminal, the script will also exit. This is not a problem if you add nohup to the front. His role is to generate a nohup file in the current directory, the drop process accidentally interrupted, and the output information recorded in the Nohup.

Screen
Screen is to open a new terminal, using this tool to ensure that the task is not terminated by exiting a terminal.

[root@cent01 test]# screen/input command screen will open a terminal, CTRL + A and then Ctrl+d will exit the terminal.
[Detached from 17799.pts-1.cent01]  [root@cent01 test]# screen [detached from 17834.pts-1.cent01] [root@cent01 test]# screen-ls//list which screen terminals are available and their numbers There
    are screens on:17834.pts-1.cent01 (Detached) 17799.pts-1.cent01 (Detached) 14030.pts-1.cent01 (Detached)

13942.PTS-1.CENT01 (Detached) 4 Sockets in/var/run/screen/s-root. [root@cent01 test]# screen-r 13942//Enter screen 13942 [root@cent01 test]# screen-s ' abc '//use-s to name a screen terminal to avoid confusing which terminal is
role.
[Detached from 17928.ABC] [root@cent01 test]# screen-ls There are screens on:17928.abc (Detached) 17834.pts-1.cent01 (Detached) 177 99.PTS-1.CENT01 (Detached) 14030.pts-1.cent01 (Detached) 13942.pts-1.cent01 (Detached) 5 Sockets in/var/run/sc Reen/s-root. 

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.