⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 system.html

📁 Shall高级编程
💻 HTML
📖 第 1 页 / 共 5 页
字号:
BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#! /bin/sh   2&nbsp;## Duplicate DaveG's ident-scan thingie using netcat. Oooh, he'll be p*ssed.   3&nbsp;## Args: target port [port port port ...]   4&nbsp;## Hose stdout _and_ stderr together.   5&nbsp;##   6&nbsp;##  Advantages: runs slower than ident-scan, giving remote inetd less cause   7&nbsp;##+ for alarm, and only hits the few known daemon ports you specify.   8&nbsp;##  Disadvantages: requires numeric-only port args, the output sleazitude,   9&nbsp;##+ and won't work for r-services when coming from high source ports.  10&nbsp;# Script author: Hobbit &#60;hobbit@avian.org&#62;  11&nbsp;# Used in ABS Guide with permission.  12&nbsp;  13&nbsp;# ---------------------------------------------------  14&nbsp;E_BADARGS=65       # Need at least two args.  15&nbsp;TWO_WINKS=2        # How long to sleep.  16&nbsp;THREE_WINKS=3  17&nbsp;IDPORT=113         # Authentication "tap ident" port.  18&nbsp;RAND1=999  19&nbsp;RAND2=31337  20&nbsp;TIMEOUT0=9  21&nbsp;TIMEOUT1=8  22&nbsp;TIMEOUT2=4  23&nbsp;# ---------------------------------------------------  24&nbsp;  25&nbsp;case "${2}" in  26&nbsp;  "" ) echo "Need HOST and at least one PORT." ; exit $E_BADARGS ;;  27&nbsp;esac  28&nbsp;  29&nbsp;# Ping 'em once and see if they *are* running identd.  30&nbsp;nc -z -w $TIMEOUT0 "$1" $IDPORT || \  31&nbsp;{ echo "Oops, $1 isn't running identd." ; exit 0 ; }  32&nbsp;#  -z scans for listening daemons.  33&nbsp;#     -w $TIMEOUT = How long to try to connect.  34&nbsp;  35&nbsp;# Generate a randomish base port.  36&nbsp;RP=`expr $$ % $RAND1 + $RAND2`  37&nbsp;  38&nbsp;TRG="$1"  39&nbsp;shift  40&nbsp;  41&nbsp;while test "$1" ; do  42&nbsp;  nc -v -w $TIMEOUT1 -p ${RP} "$TRG" ${1} &#60; /dev/null &#62; /dev/null &#38;  43&nbsp;  PROC=$!  44&nbsp;  sleep $THREE_WINKS  45&nbsp;  echo "${1},${RP}" | nc -w $TIMEOUT2 -r "$TRG" $IDPORT 2&#62;&#38;1  46&nbsp;  sleep $TWO_WINKS  47&nbsp;  48&nbsp;# Does this look like a lamer script or what . . . ?  49&nbsp;# ABS Guide author comments: "Ain't really all that bad . . .  50&nbsp;#+                            kinda clever, actually."  51&nbsp;  52&nbsp;  kill -HUP $PROC  53&nbsp;  RP=`expr ${RP} + 1`  54&nbsp;  shift  55&nbsp;done  56&nbsp;  57&nbsp;exit $?  58&nbsp;  59&nbsp;#  Notes:  60&nbsp;#  -----  61&nbsp;  62&nbsp;#  Try commenting out line 30 and running this script  63&nbsp;#+ with "localhost.localdomain 25" as arguments.  64&nbsp;  65&nbsp;#  For more of Hobbit's 'nc' example scripts,  66&nbsp;#+ look in the documentation:  67&nbsp;#+ the /usr/share/doc/nc-X.XX/scripts directory.</PRE></TD></TR></TABLE><HR></DIV><P>	      And, of course, there's Dr. Andrew Tridgell's notorious	      one-line script in the BitKeeper Affair:	        <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;echo clone | nc thunk.org 5000 &#62; e2fsprogs.dat</PRE></TD></TR></TABLE>	    </P></DD><DT><ANAME="FREEREF"></A><BCLASS="COMMAND">free</B></DT><DD><P>Shows memory and cache usage in tabular form. The	      output of this command lends itself to parsing, using	      <AHREF="textproc.html#GREPREF">grep</A>, <AHREF="awk.html#AWKREF">awk</A> or <BCLASS="COMMAND">Perl</B>. The	      <BCLASS="COMMAND">procinfo</B> command shows all the	      information that <BCLASS="COMMAND">free</B> does, and much	      more.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><BCLASS="COMMAND">free</B> <TTCLASS="COMPUTEROUTPUT">                total       used       free     shared    buffers     cached   Mem:         30504      28624       1880      15820       1608       16376   -/+ buffers/cache:      10640      19864   Swap:        68540       3128      65412</TT></PRE></TD></TR></TABLE><P>To show unused RAM memory:</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><BCLASS="COMMAND">free | grep Mem | awk '{ print $4 }'</B> <TTCLASS="COMPUTEROUTPUT">1880</TT></PRE></TD></TR></TABLE></DD><DT><ANAME="PROCINFOREF"></A><BCLASS="COMMAND">procinfo</B></DT><DD><P>Extract and list information and statistics from the	      <AHREF="devproc.html#DEVPROCREF"><TTCLASS="FILENAME">/proc</TT>	      pseudo-filesystem</A>. This gives a very extensive and	      detailed listing.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>procinfo | grep Bootup</B></TT> <TTCLASS="COMPUTEROUTPUT">Bootup: Wed Mar 21 15:15:50 2001    Load average: 0.04 0.21 0.34 3/47 6829</TT></PRE></TD></TR></TABLE></DD><DT><ANAME="LSDEVREF"></A><BCLASS="COMMAND">lsdev</B></DT><DD><P>List devices, that is, show installed hardware.</P><P>	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>lsdev</B></TT> <TTCLASS="COMPUTEROUTPUT">Device            DMA   IRQ  I/O Ports ------------------------------------------------ cascade             4     2  dma                          0080-008f dma1                         0000-001f dma2                         00c0-00df fpu                          00f0-00ff ide0                     14  01f0-01f7 03f6-03f6 ...</TT> 	      </PRE></TD></TR></TABLE>	      </P></DD><DT><ANAME="DUREF"></A><BCLASS="COMMAND">du</B></DT><DD><P>Show (disk) file usage, recursively. Defaults to current	      working directory, unless otherwise specified.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><BCLASS="COMMAND">du -ach</B> <TTCLASS="COMPUTEROUTPUT">1.0k    ./wi.sh 1.0k    ./tst.sh 1.0k    ./random.file 6.0k    . 6.0k    total</TT></PRE></TD></TR></TABLE></DD><DT><ANAME="DFREF"></A><BCLASS="COMMAND">df</B></DT><DD><P>Shows filesystem usage in tabular form.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><BCLASS="COMMAND">df</B> <TTCLASS="COMPUTEROUTPUT">Filesystem           1k-blocks      Used Available Use% Mounted on /dev/hda5               273262     92607    166547  36% / /dev/hda8               222525    123951     87085  59% /home /dev/hda7              1408796   1075744    261488  80% /usr</TT></PRE></TD></TR></TABLE></DD><DT><ANAME="DMESGREF"></A><BCLASS="COMMAND">dmesg</B></DT><DD><P>Lists all system bootup messages to	      <TTCLASS="FILENAME">stdout</TT>. Handy for debugging and	      ascertaining which device drivers were installed	      and which system interrupts in use. The output	      of <BCLASS="COMMAND">dmesg</B> may, of course, be	      parsed with <AHREF="textproc.html#GREPREF">grep</A>,	      <AHREF="sedawk.html#SEDREF">sed</A>, or <AHREF="awk.html#AWKREF">awk</A> from within a script.</P><P>	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>dmesg | grep hda</B></TT> <TTCLASS="COMPUTEROUTPUT">Kernel command line: ro root=/dev/hda2 hda: IBM-DLGA-23080, ATA DISK drive hda: 6015744 sectors (3080 MB) w/96KiB Cache, CHS=746/128/63 hda: hda1 hda2 hda3 &#60; hda5 hda6 hda7 &#62; hda4</TT> 	      </PRE></TD></TR></TABLE>	    </P></DD><DT><ANAME="STATREF"></A><BCLASS="COMMAND">stat</B></DT><DD><P>Gives detailed and verbose <SPANCLASS="emphasis"><ICLASS="EMPHASIS">stat</I></SPAN>istics 	      on a given file (even a directory or device file) or set	      of files.</P><P>	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>stat test.cru</B></TT> <TTCLASS="COMPUTEROUTPUT">  File: "test.cru"   Size: 49970        Allocated Blocks: 100          Filetype: Regular File   Mode: (0664/-rw-rw-r--)         Uid: (  501/ bozo)  Gid: (  501/ bozo) Device:  3,8   Inode: 18185     Links: 1     Access: Sat Jun  2 16:40:24 2001 Modify: Sat Jun  2 16:40:24 2001 Change: Sat Jun  2 16:40:24 2001</TT> 	      </PRE></TD></TR></TABLE>	    </P><P>If the target file does not exist, <BCLASS="COMMAND">stat</B>	      returns an error message.</P><P>	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>stat nonexistent-file</B></TT> <TTCLASS="COMPUTEROUTPUT">nonexistent-file: No such file or directory</TT> 	      </PRE></TD></TR></TABLE>	    </P><P>In a script, you can use <BCLASS="COMMAND">stat</B> to extract	      information about files (and filesystems) and set variables	      accordingly.</P><P>	      <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING">   1&nbsp;#!/bin/bash   2&nbsp;# fileinfo2.sh   3&nbsp;   4&nbsp;# Per suggestion of Jo雔 Bourquard and . . .   5&nbsp;# http://www.linuxquestions.org/questions/showthread.php?t=410766   6&nbsp;   7&nbsp;   8&nbsp;FILENAME=testfile.txt   9&nbsp;file_name=$(stat -c%n "$FILENAME")   # Same as "$FILENAME" of course.  10&nbsp;file_owner=$(stat -c%U "$FILENAME")  11&nbsp;file_size=$(stat -c%s "$FILENAME")  12&nbsp;#  Certainly easier than using "ls -l $FILENAME"  13&nbsp;#+ and then parsing with sed.  14&nbsp;file_inode=$(stat -c%i "$FILENAME")  15&nbsp;file_type=$(stat -c%F "$FILENAME")  16&nbsp;file_access_rights=$(stat -c%A "$FILENAME")  17&nbsp;  18&nbsp;echo "File name:          $file_name"  19&nbsp;echo "File owner:         $file_owner"  20&nbsp;echo "File size:          $file_size"  21&nbsp;echo "File inode:         $file_inode"  22&nbsp;echo "File type:          $file_type"  23&nbsp;echo "File access rights: $file_access_rights"  24&nbsp;  25&nbsp;exit 0  26&nbsp;  27&nbsp;sh fileinfo2.sh  28&nbsp;  29&nbsp;File name:          testfile.txt  30&nbsp;File owner:         bozo  31&nbsp;File size:          418  32&nbsp;File inode:         1730378  33&nbsp;File type:          regular file  34&nbsp;File access rights: -rw-rw-r--</PRE></TD></TR></TABLE>	    </P></DD><DT><ANAME="VMSTATREF"></A><BCLASS="COMMAND">vmstat</B></DT><DD><P>Display virtual memory statistics.</P><P>	    <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>vmstat</B></TT> <TTCLASS="COMPUTEROUTPUT">   procs                      memory    swap          io system         cpu r  b  w   swpd   free   buff  cache  si  so    bi    bo   in    cs  us  sy id 0  0  0      0  11040   2636  38952   0   0    33     7  271    88   8   3 89</TT> 	    </PRE></TD></TR></TABLE>	    </P></DD><DT><ANAME="NETSTATREF"></A><BCLASS="COMMAND">netstat</B></DT><DD><P>Show current network statistics and information, 	      such as routing tables and active connections. This utility	      accesses information in <TTCLASS="FILENAME">/proc/net</TT>	      (<AHREF="devproc.html">Chapter 27</A>). See <AHREF="procref1.html#CONSTAT">Example 27-3</A>.</P><P><BCLASS="COMMAND">netstat -r</B> is equivalent to <AHREF="system.html#ROUTEREF">route</A>.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>netstat</B></TT> <TTCLASS="COMPUTEROUTPUT">Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address           Foreign Address         State       Active UNIX domain sockets (w/o servers) Proto RefCnt Flags       Type       State         I-Node Path unix  11     [ ]         DGRAM                    906    /dev/log unix  3      [ ]         STREAM     CONNECTED     4514   /tmp/.X11-unix/X0 unix  3      [ ]         STREAM     CONNECTED     4513 . . .</TT></PRE></TD></TR></TABLE><DIVCLASS="NOTE"><TABLECLASS="NOTE"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/note.png"HSPACE="5"ALT="Note"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>A <BCLASS="COMMAND">netstat -lptu</B> shows <AHREF="devproc.html#SOCKETREF">sockets</A> that are listening	    to ports, and the associated processes. This can be useful	    for determining whether a computer has been hacked or	    compromised.</P></TD></TR></TABLE></DIV></DD><DT><ANAME="UPTIMEREF"></A><BCLASS="COMMAND">uptime</B></DT><DD><P>Shows how long the system has been running, along with	      associated statistics.</P><P>	    <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>uptime</B></TT> <TTCLASS="COMPUTEROUTPUT">10:28pm  up  1:57,  3 users,  load average: 0.17, 0.34, 0.27</TT></PRE></TD></TR></TABLE>	    </P><DIVCLASS="NOTE"><TABLECLASS="NOTE"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/note.png"HSPACE="5"ALT="Note"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>A <ICLASS="FIRSTTERM">load average</I> of 1 or less	      indicates that the system handles processes immediately. A load	      average greater than 1 means that processes are being queued. When	      the load average gets above 3, then system performance is	      significantly degraded.</P></TD></TR></TABLE></DIV></DD><DT><ANAME="HNAMEREF"></A><BCLASS="COMMAND">hostname</B></DT><DD><P>Lists the system's host name. This command sets the host	      name in an <TTCLASS="FILENAME">/etc/rc.d</TT>	      setup script (<TTCLASS="FILENAME">/etc/rc.d/rc.sysinit</TT>	      or similar).  It is equivalent to <BCLASS="COMMAND">uname	      -n</B>,  and a counterpart to the <AHREF="variables2.html#HOSTNAMEREF">$HOSTNAME</A> internal	      variable.</P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>hostname</B></TT> <TTCLASS="COMPUTEROUTPUT">localhost.localdomain</TT>  <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>echo $HOSTNAME</B></TT> <TTCLASS="COMPUTEROUTPUT">localhost.localdomain</TT></PRE></TD></TR></TABLE><P>Similar to the <BCLASS="COMMAND">hostname</B> command are the

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -