📄 communications.html
字号:
> of <SPANCLASS="ERRORCODE">0</SPAN>. This can be tested for in a script.</P><P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 HNAME=nastyspammer.com 2 # HNAME=$HOST # Debug: test for localhost. 3 count=2 # Send only two pings. 4 5 if [[ `ping -c $count "$HNAME"` ]] 6 then 7 echo ""$HNAME" still up and broadcasting spam your way." 8 else 9 echo ""$HNAME" seems to be down. Pity." 10 fi</PRE></TD></TR></TABLE></P></DD><DT><ANAME="WHOISREF"></A><BCLASS="COMMAND">whois</B></DT><DD><P>Perform a DNS (Domain Name System) lookup. The <TTCLASS="OPTION">-h</TT> option permits specifying which particular <ICLASS="FIRSTTERM">whois</I> server to query. See <AHREF="othertypesv.html#EX18">Example 4-6</A> and <AHREF="communications.html#SPAMLOOKUP">Example 15-39</A>.</P></DD><DT><ANAME="FINGERREF"></A><BCLASS="COMMAND">finger</B></DT><DD><P>Retrieve information about users on a network. Optionally, this command can display a user's <TTCLASS="FILENAME">~/.plan</TT>, <TTCLASS="FILENAME">~/.project</TT>, and <TTCLASS="FILENAME">~/.forward</TT> files, if present.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>finger</B></TT> <TTCLASS="COMPUTEROUTPUT">Login Name Tty Idle Login Time Office Office Phone bozo Bozo Bozeman tty1 8 Jun 25 16:59 bozo Bozo Bozeman ttyp0 Jun 25 16:59 bozo Bozo Bozeman ttyp1 Jun 25 17:07</TT> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>finger bozo</B></TT> <TTCLASS="COMPUTEROUTPUT">Login: bozo Name: Bozo Bozeman Directory: /home/bozo Shell: /bin/bash Office: 2355 Clown St., 543-1234 On since Fri Aug 31 20:13 (MST) on tty1 1 hour 38 minutes idle On since Fri Aug 31 20:13 (MST) on pts/0 12 seconds idle On since Fri Aug 31 20:13 (MST) on pts/1 On since Fri Aug 31 20:31 (MST) on pts/2 1 hour 16 minutes idle No mail. No Plan.</TT> </PRE></TD></TR></TABLE> </P><P>Out of security considerations, many networks disable <BCLASS="COMMAND">finger</B> and its associated daemon. <ANAME="AEN12186"HREF="#FTN.AEN12186">[1]</A> </P></DD><DT><ANAME="CHFNREF"></A><BCLASS="COMMAND">chfn</B></DT><DD><P>Change information disclosed by the <BCLASS="COMMAND">finger</B> command.</P></DD><DT><ANAME="VRFYREF"></A><BCLASS="COMMAND">vrfy</B></DT><DD><P>Verify an Internet e-mail address.</P><P>This command seems to be missing from newer Linux distros.</P></DD></DL></DIV><DIVCLASS="VARIABLELIST"><P><B><ANAME="COMMREMOTE1"></A>Remote Host Access</B></P><DL><DT><ANAME="RXREF"></A><BCLASS="COMMAND">sx</B>, <BCLASS="COMMAND">rx</B></DT><DD><P>The <BCLASS="COMMAND">sx</B> and <BCLASS="COMMAND">rx</B> command set serves to transfer files to and from a remote host using the <ICLASS="FIRSTTERM">xmodem</I> protocol. These are generally part of a communications package, such as <BCLASS="COMMAND">minicom</B>.</P></DD><DT><ANAME="RZREF"></A><BCLASS="COMMAND">sz</B>, <BCLASS="COMMAND">rz</B></DT><DD><P>The <BCLASS="COMMAND">sz</B> and <BCLASS="COMMAND">rz</B> command set serves to transfer files to and from a remote host using the <ICLASS="FIRSTTERM">zmodem</I> protocol. <ICLASS="FIRSTTERM">Zmodem</I> has certain advantages over <ICLASS="FIRSTTERM">xmodem</I>, such as faster transmission rate and resumption of interrupted file transfers. Like <BCLASS="COMMAND">sx</B> and <BCLASS="COMMAND">rx</B>, these are generally part of a communications package.</P></DD><DT><ANAME="FTPREF"></A><BCLASS="COMMAND">ftp</B></DT><DD><P>Utility and protocol for uploading / downloading files to or from a remote host. An ftp session can be automated in a script (see <AHREF="here-docs.html#EX72">Example 18-6</A>, <AHREF="contributed-scripts.html#ENCRYPTEDPW">Example A-4</A>, and <AHREF="contributed-scripts.html#FTPGET">Example A-13</A>).</P></DD><DT><ANAME="UUCPREF"></A><BCLASS="COMMAND">uucp</B>, <ANAME="UUXREF"></A><BCLASS="COMMAND">uux</B>, <ANAME="CUREF"></A><BCLASS="COMMAND">cu</B></DT><DD><P><BCLASS="COMMAND">uucp</B>: <ICLASS="FIRSTTERM">UNIX to UNIX copy</I>. This is a communications package for transferring files between UNIX servers. A shell script is an effective way to handle a <BCLASS="COMMAND">uucp</B> command sequence.</P><P>Since the advent of the Internet and e-mail, <BCLASS="COMMAND">uucp</B> seems to have faded into obscurity, but it still exists and remains perfectly workable in situations where an Internet connection is not available or appropriate. The advantage of <BCLASS="COMMAND">uucp</B> is that it is fault-tolerant, so even if there is a service interruption the copy operation will resume where it left off when the connection is restored.</P><P>---</P><P><BCLASS="COMMAND">uux</B>: <ICLASS="FIRSTTERM">UNIX to UNIX execute</I>. Execute a command on a remote system. This command is part of the <BCLASS="COMMAND">uucp</B> package.</P><P>---</P><P><BCLASS="COMMAND">cu</B>: <BCLASS="COMMAND">C</B>all <BCLASS="COMMAND">U</B>p a remote system and connect as a simple terminal. It is a sort of dumbed-down version of <AHREF="communications.html#TELNETREF">telnet</A>. This command is part of the <BCLASS="COMMAND">uucp</B> package.</P></DD><DT><ANAME="TELNETREF"></A><BCLASS="COMMAND">telnet</B></DT><DD><P>Utility and protocol for connecting to a remote host.</P><DIVCLASS="CAUTION"><TABLECLASS="CAUTION"WIDTH="90%"BORDER="0"><TR><TDWIDTH="25"ALIGN="CENTER"VALIGN="TOP"><IMGSRC="common/caution.png"HSPACE="5"ALT="Caution"></TD><TDALIGN="LEFT"VALIGN="TOP"><P>The <ICLASS="FIRSTTERM">telnet</I> protocol contains security holes and should therefore probably be avoided. Its use within a shell script is <SPANCLASS="emphasis"><ICLASS="EMPHASIS">not</I></SPAN> recommended.</P></TD></TR></TABLE></DIV></DD><DT><ANAME="WGETREF"></A><BCLASS="COMMAND">wget</B></DT><DD><P>The <BCLASS="COMMAND">wget</B> utility <ICLASS="FIRSTTERM">noninteractively</I> retrieves or downloads files from a Web or ftp site. It works well in a script.</P><P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 wget -p http://www.xyz23.com/file01.html 2 # The -p or --page-requisite option causes wget to fetch all files 3 #+ required to display the specified page. 4 5 wget -r ftp://ftp.xyz24.net/~bozo/project_files/ -O $SAVEFILE 6 # The -r option recursively follows and retrieves all links 7 #+ on the specified site. 8 9 wget -c ftp://ftp.xyz25.net/bozofiles/filename.tar.bz2 10 # The -c option lets wget resume an interrupted download. 11 # This works with ftp servers and many HTTP sites.</PRE></TD></TR></TABLE></P><DIVCLASS="EXAMPLE"><HR><ANAME="QUOTEFETCH"></A><P><B>Example 15-41. Getting a stock quote</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 #!/bin/bash 2 # quote-fetch.sh: Download a stock quote. 3 4 5 E_NOPARAMS=66 6 7 if [ -z "$1" ] # Must specify a stock (symbol) to fetch. 8 then echo "Usage: `basename $0` stock-symbol" 9 exit $E_NOPARAMS 10 fi 11 12 stock_symbol=$1 13 14 file_suffix=.html 15 # Fetches an HTML file, so name it appropriately. 16 URL='http://finance.yahoo.com/q?s=' 17 # Yahoo finance board, with stock query suffix. 18 19 # ----------------------------------------------------------- 20 wget -O ${stock_symbol}${file_suffix} "${URL}${stock_symbol}" 21 # ----------------------------------------------------------- 22 23 24 # To look up stuff on http://search.yahoo.com: 25 # ----------------------------------------------------------- 26 # URL="http://search.yahoo.com/search?fr=ush-news&p=${query}" 27 # wget -O "$savefilename" "${URL}" 28 # ----------------------------------------------------------- 29 # Saves a list of relevant URLs. 30 31 exit $? 32 33 # Exercises: 34 # --------- 35 # 36 # 1) Add a test to ensure the user running the script is on-line. 37 # (Hint: parse the output of 'ps -ax' for "ppp" or "connect." 38 # 39 # 2) Modify this script to fetch the local weather report, 40 #+ taking the user's zip code as an argument.</PRE></TD></TR></TABLE><HR></DIV><P>See also <AHREF="contributed-scripts.html#WGETTER2">Example A-32</A> and <AHREF="contributed-scripts.html#BASHPODDER">Example A-33</A>.</P></DD><DT><ANAME="LYNXREF"></A><BCLASS="COMMAND">lynx</B></DT><DD><P>The <BCLASS="COMMAND">lynx</B> Web and file browser can be used inside a script (with the <TTCLASS="OPTION">-dump</TT> option) to retrieve a file from a Web or ftp site noninteractively.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 lynx -dump http://www.xyz23.com/file01.html >$SAVEFILE</PRE></TD></TR></TABLE> </P><P>With the <TTCLASS="OPTION">-traversal</TT> option, <BCLASS="COMMAND">lynx</B> starts at the HTTP URL specified as an argument, then <SPANCLASS="QUOTE">"crawls"</SPAN> through all links located on that particular server. Used together with the <TTCLASS="OPTION">-crawl</TT> option, outputs page text to a log file.</P></DD><DT><ANAME="RLOGINREF"></A><BCLASS="COMMAND">rlogin</B></DT><DD><P><TTCLASS="REPLACEABLE"><I>Remote login</I></TT>, initates a session on a remote host. This command has security issues, so use <AHREF="communications.html#SSHREF">ssh</A> instead.</P></DD><DT><ANAME="RSHREF"></A><BCLASS="COMMAND">rsh</B></DT><DD><P><TTCLASS="REPLACEABLE"><I>Remote shell</I></TT>, executes command(s) on a remote host. This has security issues, so use <BCLASS="COMMAND">ssh</B> instead.</P></DD><DT><ANAME="RCPREF"></A><BCLASS="COMMAND">rcp</B></DT><DD><P><TTCLASS="REPLACEABLE"><I>Remote copy</I></TT>, copies files between two different networked machines.</P></DD><DT><ANAME="RSYNCREF"></A><BCLASS="COMMAND">rsync</B></DT><DD><P><TTCLASS="REPLACEABLE"><I>Remote synchronize</I></TT>, updates (synchronizes) files between two different networked machines.</P><P> <TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="SCREEN"> <TTCLASS="PROMPT">bash$ </TT><TTCLASS="USERINPUT"><B>rsync -a ~/sourcedir/*txt /node1/subdirectory/</B></TT> </PRE></TD></TR></TABLE> </P><DIVCLASS="EXAMPLE"><HR><ANAME="FC4UPD"></A><P><B>Example 15-42. Updating FC4</B></P><TABLEBORDER="0"BGCOLOR="#E0E0E0"WIDTH="90%"><TR><TD><PRECLASS="PROGRAMLISTING"> 1 #!/bin/bash 2 # fc4upd.sh 3 4 # Script author: Frank Wang. 5 # Slight stylistic modifications by ABS Guide author. 6 # Used in ABS Guide with permission. 7 8 9 # Download Fedora Core 4 update from mirror site using rsync. 10 # Should also work for newer Fedora Cores -- 5, 6, . . . 11 # Only download latest package if multiple versions exist, 12 #+ to save space. 13 14 URL=rsync://distro.ibiblio.org/fedora-linux-core/updates/ 15 # URL=rsync://ftp.kddilabs.jp/fedora/core/updates/ 16 # URL=rsync://rsync.planetmirror.com/fedora-linux-core/updates/ 17 18 DEST=${1:-/var/www/html/fedora/updates/} 19 LOG=/tmp/repo-update-$(/bin/date +%Y-%m-%d).txt 20 PID_FILE=/var/run/${0##*/}.pid 21 22 E_RETURN=65 # Something unexpected happened. 23 24 25 # General rsync options 26 # -r: recursive download
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -