Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Cooper M.Advanced bash-scripting guide.2002.pdf
Скачиваний:
15
Добавлен:
23.08.2013
Размер:
916.67 Кб
Скачать

Advanced Bash−Scripting Guide

author's very own cruft (see Example A−4).

Miscellaneous

make

Utility for building and compiling binary packages. This can also be used for any set of operations that is triggered by incremental changes in source files.

The make command checks a Makefile, a list of file dependencies and operations to be carried out.

install

Special purpose file copying command, similar to cp, but capable of setting permissions and attributes of the copied files. This command seems tailormade for installing software packages, and as such it shows up frequently in Makefiles (in the make install : section). It could likewise find use in installation scripts.

more, less

Pagers that display a text file or stream to stdout, one screenful at a time. These may be used to filter the output of a script.

12.6. Communications Commands

Information and Statistics

host

Searches for information about an Internet host by name or IP address, using DNS.

vrfy

Verify an Internet e−mail address.

nslookup

Do an Internet "name server lookup" on a host by IP address. This may be run either interactively or noninteractively, i.e., from within a script.

dig

Similar to nslookup, do an Internet or noninteractively, i.e., from within

"name server lookup" on a host. May be run either interactively a script.

traceroute

12.6. Communications Commands

174

Advanced Bash−Scripting Guide

Trace the route taken by packets sent to a remote host. This command works within a LAN, WAN, or over the Internet. The remote host may be specified by an IP address. The output of this command may be filtered by grep or sed in a pipe.

ping

Broadcast an "ICMP ECHO_REQUEST" packet to other machines, either on a local or remote network. This is a diagnostic tool for testing network connections, and it should be used with caution.

A successful ping returns an exit status of 0. This can be tested for in a script.

bash$ ping localhost

PING localhost.localdomain (127.0.0.1) from 127.0.0.1 : 56(84) bytes of data. Warning: time of day goes back, taking countermeasures.

64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=0 ttl=255 time=709 usec 64 bytes from localhost.localdomain (127.0.0.1): icmp_seq=1 ttl=255 time=286 usec

−−− localhost.localdomain ping statistics −−−

2 packets transmitted, 2 packets received, 0% packet loss round−trip min/avg/max/mdev = 0.286/0.497/0.709/0.212 ms

whois

Perform a DNS (Domain Name System) lookup. The −h option permits specifying which whois server to query. See Example 5−6.

finger

Retrieve information about a particular user on a network. Optionally, this command can display the

user's ~/.plan, ~/.project, and

~/.forward files, if present.

 

 

 

bash$ finger bozo

 

 

Login: bozo

Name: Bozo Bozeman

Directory: /home/bozo

 

Shell: /bin/bash

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.

 

 

 

 

 

Out of security considerations, many networks disable finger and its associated daemon. [31]

Remote Host Access

sx, rx

The sx and rx command set serves to transfer files to and from a remote host using the xmodem protocol. These are generally part of a communications package, such as minicom.

sz, rz

12.6. Communications Commands

175

Advanced Bash−Scripting Guide

The sz and rz command set serves to transfer files to and from a remote host using the

zmodem protocol. Zmodem has certain advantages over xmodem, such as greater transmission rate and resumption of interrupted file transfers. Like sx and rx, these are generally part of a communications package.

ftp

Utility and protocol for uploading / downloading files to / from a remote host. An ftp session can be automated in a script (see Example 17−7 , Example A−4 , and Example A−8).

cu

Call Up a remote system and connect as a simple terminal. This is a sort of dumbed−down version of telnet.

uucp

UNIX to UNIX copy. This is a communications package for transferring files between UNIX servers. A shell script is an effective way to handle a uucp command sequence.

Since the advent of the Internet and e−mail, uucp 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.

telnet

Utility and protocol for connecting to a remote host.

The telnet protocol contains security holes and should therefore probably be avoided.

rlogin

Remote login, initates a session on a remote host. This command has security issues, so use ssh instead.

rsh

Remote shell, executes command(s) on a remote host. This has security issues, so use ssh instead.

rcp

Remote copy, copies files between two different networked machines. Using rcp and similar utilities with security implications in a shell script may not be advisable. Consider, instead, using ssh or an expect script.

ssh

Secure shell, logs onto a remote host and executes commands there. This secure replacement

12.6. Communications Commands

176

Advanced Bash−Scripting Guide

for telnet, rlogin, rcp, and rsh uses identity authentication and encryption. See its manpage for details.

Local Network

write

This is a utility for terminal−to−terminal communication. It allows sending lines from your terminal (console or xterm) to that of another user. The mesg command may, of course, be used to disable write access to a terminal

Since write is interactive, it would not normally find use in a script.

Mail

vacation

This utility automatically replies to e−mails that the intended recipient is on vacation and temporarily unavailable. This runs on a network, in conjunction with sendmail, and is not applicable to a dial−up POPmail account.

12.7. Terminal Control Commands

Command Listing

tput

Initialize terminal and/or fetch information about it from terminfo data. Various options permit certain terminal operations. tput clear is the equivalent of clear, below. tput reset is the equivalent of reset, below.

bash$ tput longname

xterm terminal emulator (XFree86 4.0 Window System)

Note that stty offers a more powerful command set for controlling a terminal.

reset

Reset terminal parameters and clear text screen. As with clear, the cursor and prompt reappear in the upper lefthand corner of the terminal.

clear

The clear command simply clears the text screen at the console or in an xterm. The prompt and cursor reappear at the upper lefthand corner of the screen or xterm window. This command may be used either at the command line or in a script. See Example 10−23.

script

12.7. Terminal Control Commands

177