Sei sulla pagina 1di 34

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

MODULE IV
4.1 Backup and Its Importance One of the most important tasks of system administration is making backup copies of files on a regular basis. The backup copies are vital in three instances: when the system malfunctions and files are lost a catastrophic disaster such as a fire or earthquake occurs a user or the system administrator deletes or corrupts a file by accident. Even when you set up RAID, you still need to back up files. Although RAID provides fault tolerancehelpful in the event of disk failure it does not help when a disaster occurs or when a file is corrupted or accidentally removed. It is a good idea to have a written backup policy and to keep copies of backups in a fireproof vault or safe located in another building, at home or at a completely different facility or campus. The time to start thinking about backups is when you partition the disk. Make sure the capacity of the backup device and your partition sizes are comparable. Although you can back up a partition onto multiple volumes, it is easier not to do that and much easier to restore data from a single volume. You must back up file systems on a regular basis. Backup files are usually kept on magnetic tape or some other removable media. Exactly how often you should back up which files depends on the system and your needs. Use this criterion when determining a backup schedule: If the system crashes, how much work are you willing to lose? Ideally you would back up all files on the system every few minutes so you would never lose more than a few minutes of work. But there is a tradeoff: How often are you willing to back up the files? The backup procedure typically slows down the system for other users, it takes a certain amount of your time, and it requires that you have and store the tape or disk media holding the backup. Avoid backing up an active file system. The results may be inconsistent, and restoring from the backup may be impossible. This
Dept. of Computer Science And Applications, SJCET, Palai Page 88

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

requirement is a function of the backup program and the file system you are backing up. Another question is when to run the backup. Unless you plan to kick users off and bring the system down to single-user mode, you want to perform this task when the machine is at its quietest. Depending on the use of the system, sometimes, in the middle of the night backup can be taken. Then the backup is least likely to affect users, and the files are not likely to change as they are being read for backup. A full backup makes copies of all files, regardless of when they were created or accessed. An incremental backup makes copies of those files that have been created or modified since the lastusually fullbackup. The more people using the system, the more often you should back up the file systems. One popular schedule is to perform an incremental backup once or twice in a day and a full backup one or two times a week.

4.1.1 Choosing a Backup Medium If the local system is connected to a network, you can write your backups to a tape drive on another system. This technique is often used with networked computers to avoid the cost of having a tape drive on each computer in the network and to simplify management of backing up many computers in a network. Most likely you want to use a tape system for backups. Because tape drives hold many gigabytes of data, using tape simplifies the task of backing up the system, making it more likely that you will take care of this important task regularly. Other options for holding backups are writable CDs, DVDs and removable hard disks. These devices, although not as cost-effective or able to store as much information as tape systems, offer convenience and improved performance over using tapes.

4.2 Backup Utilities


Dept. of Computer Science And Applications, SJCET, Palai Page 89

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

A number of utilities can help you back up the system, and most work with any media. Most Linux backup utilities are based on one of the archive programs tar or cpio augment these basic programs with bookkeeping support for managing backups conveniently. You can use any of the tar, cpio, or dump/restore utilities to construct full or partial backups of the system. Each utility constructs a large file that contains, or archives, other files. In addition to file contents, an archive includes header information for each file it holds. This header information can be used when extracting files from the archive to restore file permissions and modification dates. An archive file can be saved to disk, written to tape or shipped across the network while it is being created. In addition to helping you back up the system, these programs offer a convenient way to bundle files for distribution to other sites. The tar program is often used for this purpose, and some software packages available on the Internet are bundled as tar archive files. The Advanced Maryland Automatic Network Disk Archiver (AMANDA) utility is one of the most popular backup systems that uses dump or tar and takes advantage of Samba to back up Windows systems. The amanda utility backs up a LAN of heterogeneous hosts to a single tape drive.

4.2.1 tar: Archives Files The tartape archiveutility stores and retrieves files from an archive and can compress the archive to conserve space. If you do not specify an archive device, tar uses standard output and standard input. With the f option, tar uses the argument to f as the name of the archive device. You can use this option to refer to a device on another system on the network. Although tar has many options, you need only a few in most situations. Table 4.1 shows the various options of tar command.

Dept. of Computer Science And Applications, SJCET, Palai Page 90

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

Table 4.1
Option append (r) create (c) delete diff (d) extract (x) help list (t) update (u) Effect Appends files to an archive Creates a new archive Deletes files in an archive, not on tapes Compares files in an archive with disk files Extracts files from an archive Displays a help list of tar options Lists the files in an archive Like the r option, but the file is not appended if a newer version is already in the archive

catenate (A) Adds one or more archives to the end of an existing archive

4.1.1 Im
Examples [root@linuxbox biju ]# tar cvzf /media/mydisk/home.tar /home/biju/ The above command creates a zipped (gzipped) home.tar archive in an external storage device (Here I used a pen drive with name mydisk). If you want to create a tar archive of your directory cprog containing all the C programs then the following command can be used. [root@linuxbox biju ]# tar cvf /media/mydisk/cprog.tar /home/biju/cprog The archive created would be in the pen drive as cprog.tar. This can be extracted by using the following command.

[root@linuxbox biju]# tar -xvf cprog.tar This command would generate a folder called cprog and all the files in it. Just note the difference between the commandswe use option c for creation and x for extracting the files. Both use option v to make it
Dept. of Computer Science And Applications, SJCET, Palai Page 91

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

verbose. The option z creates a compressed (gzipped with .gz extension) archive after creation of tar archive. Again if we use a j option then the compression will be bz2 format. To extract we need to uncompress it first, and then use tar utility. [Detailed discussions on file compress utilities are given in article 4.3. Please do refer for a better understanding] To take the back of any users home directory, to the same disk with different partition called backup, using tar is shown below. [root@linuxbox squid ]# tar cvf /backup/home_biju.tar /home/biju The above command would generate a tar archive called home_biju.tar in the directory, /backup/

4.2.2 cpio: Archives Files The cpio (copy in/out) program is similar to tar but can use archive files in a variety of formats, including the one used by tar. Normally cpio reads the names of the files to insert into the archive from standard input and produces the archive file as standard output. When extracting files from an archive, cpio reads the archive as standard input. cpio command creates and un-creates archived cpio files. It is capable of copying files to things other than a hard disk. Probably, this command is also used to backup and restore files. SYNTAX: The Syntax is:

cpio [options]

Various options of cpio command are shown in table 4.2 Table 4.2
-i -o -p -c -d Extracts files from the standard input. Reads the standard input to obtain a list of path names and copies those files onto the standard output. Reads the standard input to obtain a list of path names of files. Read or write header information in ASCII character form for portability. Creates directories as needed.

Dept. of Computer Science And Applications, SJCET, Palai Page 92

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

-u -m -v

Copy unconditionally (normally, an older file will not replace a newer file with the same name). Retain previous file modification time. This option is ineffective on directories that are being copied. Verbose.Print a list of file names.

Examples

[root@linuxbox root ]# find . -print | cpio -ocv > /dev/fd0 Find list of files and directories and then copy those to floppy drive. The options used are o,c,v

[root@linuxbox root ]# find . -print | cpio -dumpv /home/biju Find list of files and directories and then copy or backup those to user bijus home directory.

[root@linuxbox root ]# cpio -icuvd < /home/biju This command restores the files back from the home directory.

4.2.3 dump, restore: Back Up and Restore Filesystems The dump utility backs up either an entire filesystem or only those files that have changed since the last dump. The restore utility restores an entire filesystem, an individual file or a directory hierarchy. You will get the best results if you perform a backup on a quiescent system so that the files are not changing as you make the backup. dump command makes backup of filesystem or file and directories.

cpio, tar is suitable for archiving specific files or directories. dump is suitable for archiving whole filesystems.

Dept. of Computer Science And Applications, SJCET, Palai Page 93

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

SYNTAX: The Syntax is dump [options] [dump-file] [File-system or file or directories]. Various options are given in table 4.3

Table 4.3

-[level] -f -u -v -e Example

The dump level any integer Make the backup in a specified file Updates /etc/dumpdats file for the backup made Displays Verbose Information Exclude inode while making backup

[root@linuxbox root ]# dump -0uf /dev/sdb1 /

This command backs up all filesincluding directories and special files on the root (/) partition to a pendrive. The option specifies that the entire filesystem is to be backed up a full backup). There are ten dump levels: 09. Zero is the highestmost completelevel and always backs up the entire filesystem. Each additional level is incremental with respect to the level above it. For example, 1 is incremental to 0 and backs up only files that have changed since the last level 0 dump, and 2 is incremental to 1 and backs up only files that have changed since the last level 1 dump and so on. You can construct a very flexible schedule using this scheme. You do not need to use sequential numbers for backup levels. You can perform a level 0 dump, followed by level 2 and 5 dumps.
Dept. of Computer Science And Applications, SJCET, Palai Page 94

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

The u option updates the /etc/dumpdates file with filesystem, date and dump level information for use by the next incremental dump. The f option and its argument write the backup to the device named /dev/sdb1 The following command makes a partial backup containing all files that have changed since the last level 0 dump. The first argument is a 1, specifying a level 1 dump:

[root@linuxbox root ]# dump -1uf /dev/sdb1 /

To restore an entire filesystem from a pendrive, first restore the most recent complete (level 0) backup. Perform this operation carefully because restore can overwrite the existing filesystem. When you are logged in as Superuser, cd to the directory the filesystem is mounted on and give this command: [root@linuxbox root ]# restore -if /dev/sdb1

The i option invokes an interactive mode that allows you to choose which files and directories to restore. As with dump, the f option specifies the name of the device that the backup medium is mounted on. When restore finishes, load the next lower level (higher-number) dump tape and issue the same restore command. If multiple incremental dumps have been made at a particular level, always restore with the most recent one. You do not need to invoke restore with special arguments to restore an incremental dump. It will restore whatever appears on the disk where the backup is taken with dump. You can also use restore to extract individual files from a tape by using the x option and specifying the filenames on the command line. Whenever you restore a file, the restored file will appear in the working directory. Before restoring files, make sure you are working in the correct directory.

Dept. of Computer Science And Applications, SJCET, Palai Page 95

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

The following commands restore the /etc/nsswitch.conf file from the tape on /dev/sdb1. The filename of the dumped file does not begin with / because all dumped pathnames are relative to the filesystem that you dumped in this case /. Because the restore command is given from the / directory, the file will be restored to its original location of /etc/nsswitch.conf: [root@linuxbox root ]# cd / [root@linuxbox / ]# restore -xf /dev/sdb1 etc/nsswitch.conf

If you use the x option without specifying a file or directory name to extract, the entire dumped filesystem is extracted. Use the r option to restore an entire filesystem without using the interactive interface. The following command restores the filesystem from the drive on /dev/sdb1 to the working directory without interaction: [root@linuxbox root ]# restore -rf /dev/sdb1

You can also use dump and restore to access a tape drive on another system. Specify the file/directory as host:file, where host is the hostname of the system the tape drive is on and file is the file/directory you want to dump/restore. Occasionally, restore may prompt you with the following message: You have not read any volumes yet. Unless you know which volume your file(s) are on you should start with the last volume and work towards the first. Specify next volume #: Enter 1 (one) in response to this prompt. If the filesystem spans more than one tape or disk, this prompt allows you to switch tapes. At the end of the dump, you will receive another prompt: set owner/mode for '.'? [yn] Answer y to this prompt when you are restoring entire filesystems or files that have been accidentally removed. Doing so will restore the
Dept. of Computer Science And Applications, SJCET, Palai Page 96

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

appropriate permissions to the files and directories being restored. Answer n if you are restoring a dump to a directory other than the one it was dumped from. The working directory permissions and owner will then be set to those of the person doing the restore (typically root).

4.3 Backup using rsync rsync stands for remote sync. rsync is used to perform the backup operation in UNIX / Linux. rsync utility is used to synchronize the files and directories from one location to another in an effective way. Backup location could be on local server or on remote server. This is the most used method in backing up data and files in Linux environment. Important features of rsync Speed: First time, rsync replicates the whole content between the source and destination directories. Next time, rsync transfers only the changed blocks or bytes to the destination location, which makes the transfer really fast. Security: rsync allows encryption of data using ssh protocol during transfer. Less Bandwidth: rsync uses compression and decompression of data block by block at the sending and receiving end respectively. So the bandwidth used by rsync will be always less compared to other file transfer protocols. Privileges: No special privileges are required to install and execute rsync Syntax $ rsync options source destination Source and destination could be either local or remote. In case of remote, specify the login name, remote server name and location. Example Synchronize Files From Local to Remote rsync allows you to synchronize files/directories between the local and remote system. [root@linuxbox root ]# rsync -avz -e ssh /root/temp/ biju@172.16.48.16: /home/biju/temp/ Password: building file list ... done ./
Dept. of Computer Science And Applications, SJCET, Palai Page 97

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

rpm/ rpm/Basenames rpm/Conflictname sent 15810261 bytes received 412 bytes 2432411.23 bytes/sec total size is 45305958 speedup is 2.87 While doing synchronization with the remote server, you need to specify username and ip-address of the remote server. You should also specify the destination directory on the remote server. The format is username@machinename:path
A trailing slash on the source will copy the contents of the directory, rather than generating a subdirectory of that name. Here the contents of the temp directory are copied to the /home/biju/temp directory.

As you see above, it asks for password while doing rsync from local to remote server. Sometimes you dont want to enter the password while backing up files from local to remote server. For example, if you have a backup shell script, that copies files from local to remote server using rsync, you need the ability to rsync without having to enter the password. As rsync uses a remote shell, (ssh by default) option e is used. We can configure ssh for logging in without password. So rsync also works fine without password, provided the shell used is ssh and login without password is enabled. 4.4 File Compression Utilities Both Linux and UNIX include various commands for Compressing and decompresses (read as expand compressed file). To compress files you can use gzip, bzip2 and zip commands. Table 4.5 shows the syntax, usage and example for various compress utilities in Linux To expand compressed file (decompress) gzip, bunzip2 and unzip commands can be used. Table 4.4 explains decompressing utilities.

Table 4.4 Decompressing utilities

Dept. of Computer Science And Applications, SJCET, Palai Page 98

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

Description Decompressed a file that is created gzip -d {.gz file} using gzip command. File is restored gunzip {.gz file} to their original form using this command. Decompressed a file that is created bzip2 -d {.bz2-file} using bzip2 command. File is restored bunzip2 {.bz2-file} to their original form using this command. Extract compressed files in a ZIP unzip {.zip file} archive. Untar or decompressed a file(s) that is tar -zxvf {.tgz-file} created using tar compressing through tar -jxvf {.tbz2-file} gzip and bzip2 filter

Syntax

Example(s) gzip -d mydata.doc.gz gunzip mydata.doc.gz

bzip2 -d mydata.doc.bz2 gunzip mydata.doc.bz2 unzip file.zip unzip data.zip tar -zxvf data.tgz tar -zxvf pics.tar.gz *.jpg tar -jxvf data.tbz2

Table 4.5 Compressing utilities in Linux

Description Example(s) gzip compress the size of the given files using Lempel-Ziv coding gzip mydata.doc gzip {filename} (LZ77). Whenever possible, each gzip *.jpg file is replaced by one with the extension .gz. bzip2 compresses files using the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding. Compression is bzip2 mydata.doc generally considerably better than bzip2 {filename} bzip2 *.jpg that achieved by bzip command (LZ77/LZ78-based compressors). Whenever possible, each file is replaced by one with the extension .bz2. zip is a compression and file zip {.zip-filename} packaging utility for Unix/Linux. zip mydata.zip mydata.doc {filename-toEach file is stored in single .zip zip data.zip *.doc compress} {.zip-filename} file with the extension .zip. tar -zcvf {.tgz-file} The GNU tar is archiving utility but tar -zcvf data.tgz *.doc {files} it can be use to compressing large tar -zcvf pics.tar.gz *.jpg tar -jcvf {.tbz2-file} file(s). GNU tar supports both *.png {files} archive compressing through gzip tar -jcvf data.tbz2 *.doc
Dept. of Computer Science And Applications, SJCET, Palai Page 99

Syntax

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

and bzip2. option -z: uses gzip compress and -j: uses bzip2 compress

4.5 Communication Facilities in Linux You can use a variety of network tools to perform tasks such as obtaining information about other systems on your network, accessing other systems, and communicating directly with other users. Network information can be obtained using utilities such as ping, finger, traceroute, and host. Talk, ICQ, and IRC clients enable you to communicate directly with other users on your network. Telnet performs a remote login to an account you may have on another system connected on your network. Some tools have a corresponding K Desktop or GNOME version. In addition, your network may make use of network remote access commands. These are useful for smaller networks and enable you to access remote systems directly to copy files or execute commands and also to communicate with other users. 4.5.1 mesg This command lets you control if other people (users) can use the write command, to send text to you over the screen.

Syntax : mesg [n|y]

n y

Prevents the messages from others popping up on your screen. Allows messages to appear on your screen.

Typing this command by itself will display whether or not the mesg service is enabled. For example, it may display: "is y", indicating that it is enabled. Typing n or why after the command would enable or disable this command. When this command is disabled non-root users will be unable to to send messages to you using message commands such as talk or write.
Dept. of Computer Science And Applications, SJCET, Palai Page 100

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

If no option is given, mesg prints out the current access state of your terminal. mesg assumes that it's standard input is connected to your terminal. That also means that if you are logged in multiple times, you can get/set the mesg status of other sessions by using redirection. For example "mesg n < /dev/pts/46".

4.5.2 who Linux who command shows who is logged on to the system. This is a useful command for a Linux system administrator because they can check how many users currently logged in the system and who they are. The Linux who command offers some options that user can use to see more details about users such as login time, terminal used and process id. However that is not the only things the who command can do. We can also use Linux who command to check when was the Linux system last booted and the current system's run level.

Syntax who [-a] [-b] [-d] [-H] [-l] [-m] [-nx] [-p] [-q] [-r] [-s] [-t] [-T] [-u] [ami] [ file ]

Examples of 'who' command

Dept. of Computer Science And Applications, SJCET, Palai Page 101

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

1. Get the information on currently logged in users This is done by simply running the 'who' command (without any options). Consider the following example: [root@linuxbox root ]# who

root biju pts/0 biju pts/1

tty0

2012-08-07 15:33 (:0) 2012-08-07 06:47 (:0.0) 2012-08-07 07:58 (:0.0)

2. Get the time of last system boot The is done using the -b option. Consider the following example: [root@linuxbox root ]# who b

system boot 2012-08-07 05:32

The above output gives the exact date and time of last system boot.

3. Get information on system login processes This is done using the -l option. Consider the following example:

[root@linuxbox root ]# who l

Dept. of Computer Science And Applications, SJCET, Palai Page 102

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

LOGIN LOGIN LOGIN LOGIN LOGIN LOGIN

tty4 tty5 tty2 tty3 tty6 tty1

2012-08-07 05:32 2012-08-07 05:32 2012-08-07 05:32 2012-08-07 05:32 2012-08-07 05:32 2012-08-07 05:32

1309 id=4 1313 id=5 1322 id=2 1324 id=3 1327 id=6 1492 id=1

So we can see that information related to system login processes are displayed in the output.

4. Get the hostname and user associated with stdin This is done using the -m option. Consider the following example: [root@linuxbox root ]# who m biju pts/1 2012-08-07 07:58 (:0.0) The relevant information is produced in the output.

5. Get the current run level This is done using the -r option. Consider the following example:

[biju@linuxbox biju ] $ who r

Dept. of Computer Science And Applications, SJCET, Palai Page 103

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

run-level 2 2012-08-07 05:32 So we see that the information related to current run level (which is 2) was produced in the output.

6. Get the list of user logged in This is done using the -u option. Consider the following example:

[biju@linuxbox biju ]$ who u

biju biju biju

tty7 pts/0 pts/1

2012-08-07 05:33 old 2012-08-07 06:47 00:31 2012-08-07 07:58 .

1619 (:0) 2336 (:0.0) 2336 (:0.0)

A list of logged-in users was produced in the output.

7. Get the list of user logged in and can be talked This is done using the -T option. Consider the following example:

[biju@linuxbox biju ]$ who T

biju 11mca012

+tty7 -pts/0

2012-08-07 05:33 old 2012-08-07 06:47 00:31

1619 (:0) 2336 (:0.0)

Dept. of Computer Science And Applications, SJCET, Palai Page 104

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

jyothish

+pts/1

2012-08-07 07:58 .

2336 (:0.0)

After each login name, Linux who -T command prints a character indicating the user's message status, which:

+ means allowing `write' messages. - means disallowing `write' messages. ? means cannot find terminal device.

8. Get number of users logged-in and their user names This is done using the -q option. Consider the following example:

[biju@linuxbox biju ]$ who q biju biju biju # users=3 So it can be seen that information related to number of logged-in users and their user names was produced in the output.

8. Get all the information This is done using the -a option. Consider the following example: [biju@linuxbox biju ]$ who a

system boot 2012-08-07 05:32 run-level 2 2012-08-07 05:32

Dept. of Computer Science And Applications, SJCET, Palai Page 105

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

LOGIN LOGIN LOGIN LOGIN LOGIN LOGIN biju biju biju

tty4 tty5 tty2 tty3 tty6 tty1 + tty7 + pts/0 + pts/1

2012-08-07 05:32 2012-08-07 05:32 2012-08-07 05:32 2012-08-07 05:32 2012-08-07 05:32 2012-08-07 05:32 2012-08-07 05:33 old 2012-08-07 06:47 . 2012-08-07 07:58 .

1309 id=4 1313 id=5 1322 id=2 1324 id=3 1327 id=6 1492 id=1 1619 (:0) 2336 (:0.0) 2336 (:0.0)

So we can see that all the information that 'who' can print is produced in output.

4.5.3 talk talk - talk to another user


SYNOPSIS

talk person [ttyname ] DESCRIPTION Talk is a visual communication program which copies lines from your terminal to that of another user. Options available: person If you wish to talk to someone on your own machine, then person is just the person's login name. If you wish to talk to a user on another host, then person is of the form `user@host' ttyname

Dept. of Computer Science And Applications, SJCET, Palai Page 106

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

If you wish to talk to a user who is logged in more than once, the ttyname argument may be used to indicate the appropriate terminal name, where ttyname is of the form `ttyXX' or `pts/X' When first called, talk contacts the talk daemon on the other user's machine, which sends the message Message from jyothish@mcalab.net talk: connection requested by jyothish@mcalab.net talk: respond with: talk jyothish@mcalab.net to that user. At this point, he then replies by typing talk biju@mcalab.net It doesn't matter from which machine the recipient replies, as long as his login name is the same. Once communication is established, the two parties may type simultaneously; their output will appear in separate windows. Typing control-L (^L) will cause the screen to be reprinted. The erase, kill line, and word erase characters (normally ^H, ^U, and ^W respectively) will behave normally. To exit, just type the interrupt character (normally ^C); talk then moves the cursor to the bottom of the screen and restores the terminal to its previous state. Example [biju@linuxbox biju ]$ talk jyothish

You can prevent people (other than the super-user) from talk to you with the mesg utility learned earlier.

4.5.4 write Write allows you to communicate with other users, by copying lines from your terminal to theirs. When you run the write command, the user you are writing to gets a message of the form:
Dept. of Computer Science And Applications, SJCET, Palai Page 107

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

Message from yourname@yourhost on yourtty at hh:mm ... Any further lines you enter will be copied to the specified user's terminal. If the other user wants to reply, they must run write as well. When you are done, type an end-of-file or interrupt character. The other user will see the message EOF indicating that the conversation is over. If the user you want to write to is logged in on more than one terminal, you can specify which terminal to write to by specifying the terminal name as the second operand to the write command. Alternatively, you can let write select one of the terminals - it will pick the one with the shortest idle time. This is so that if the user is logged in at work and also dialed up from home, the message will go to the right place. The traditional protocol for writing to someone is that the string `o', either at the end of a line or on a line by itself, means that it's the other person's turn to talk. The string `oo' means that the person believes the conversation to be over. You can prevent people (other than the super-user) from writing to you with the mesg command. 4.5.5 wall The wall command is used to send a message to everybody who is logged in (Broadcast) to the system. All the users who set the mesg y would receive the same. This command is useful when the system administrator wants to inform all the users about the emergency shutdown or restart process of the server system.

Example [root@linuxbox root ]# wall The system will be shut down 10mins for maintenance, so save all your files. (^D)

The length of the message is limited to 20 lines.


Dept. of Computer Science And Applications, SJCET, Palai Page 108

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

4.5.6 finger The Linux finger command displays information about the system users. We can view all information about user if we know the user account login name. Below are some examples of the Linux finger command with useful options that you can use to view user information. Type 'finger' at the command prompt without any option will give an output of users currently log in the system: [biju@mcalab~]$ finger Login biju root Name Tty Idle Login Time Office Office Phone Apr 10 13:38 Apr 10 14:38

Biju.K.V tty1 ty2

finger command can be used to find the details of a user if the login name is known.

4.5.7 chfn chfn is used to change your finger information. This information is stored in the /etc/passwd file, and is displayed by the finger program. The Linux finger command will display four pieces of information that can be changed by chfn : your real name, your work room and phone, and your home phone.

4.6 ping ping is System administration command. It confirms that a remote host is online and responding. Ping is used for verifying connectivity between two hosts on a network. It uses Internet Control Message Protocol (ICMP) and sends echo request packets to a remote IP-Address (Host) and watches for ICMP responses.
Dept. of Computer Science And Applications, SJCET, Palai Page 109

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

The ping command is used to check if there is a network connection to another computer. When a web browser fails to connect to a web site on the Internet or LAN (local area network) the cause is often the web server, which may be down or overloaded, or it may be a network failure that prevents the connection to the other machine. Therefore the first step in diagnosing the problem is to test if the network connection is working. The ping command does that without requiring a web server. In a terminal (shell window) you simply type "ping" followed by the URL or IP address of the computer you want to test. Your computer will respond with a summary of the results of each attempt to contact that computer.

One of the most common methods used to test connectivity across multiple networks is the ping command. ping sends ICMP echo packets that request a corresponding ICMP echo-reply response from the device at the target address. Because most servers will respond to a ping query it becomes a very handy tool. A lack of response could be due to: 1. A server with that IP address doesn't exist 2. The server has been configured not to respond to pings 3. A firewall or router along the network path is blocking ICMP traffic 4. You have incorrect routing. Check the routes and subnet masks on both the local and remote servers and all routers in between. A classic symptom of bad routes on a server is the ability to ping servers only on your local network and nowhere else. Use traceroute to ensure you're taking the correct path. 5. Either the source or destination device having an incorrect IP address or subnet mask. There are a variety of ICMP response codes which can help in further troubleshooting
Dept. of Computer Science And Applications, SJCET, Palai Page 110

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

Examples

[root@linuxbox root ]# ping www.google.com PING www.l.google.com (72.14.213.99): 56 data bytes 64 bytes from 72.14.213.99: icmp_seq=0 ttl=50 time=48.582 ms 64 bytes from 72.14.213.99: icmp_seq=1 ttl=50 time=48.655 ms 64 bytes from 72.14.213.99: icmp_seq=2 ttl=50 time=49.171 ms 64 bytes from 72.14.213.99: icmp_seq=3 ttl=50 time=50.554 ms ^C --- www.l.google.com ping statistics --4 packets transmitted, 4 packets received, 0% packet loss round-trip min/avg/max/stddev = 48.582/49.204/50.554/0.691 ms

You can also directly use the IP address of the machine (which you can find out with the ping command and explained in the next example). When the ping command is issued as shown, we normally use the (^c) [Control][c] key sequence to stop the command. There are times when you don't want the ping command to run forever, you may just want to issue one ping, five pings, or ten pings, etc. In that case, you use the -c option ("count") of the ping command to control the number of pings issued, as explained in the following example.

[root@mcalab root ]# ping -c 5 74.125.53.105

PING 74.125.53.105 (74.125.53.105) from mcalab.net: 56 data bytes 64 bytes from 74.125.53.105: icmp_seq=0 ttl=50 time=49.198 ms

Dept. of Computer Science And Applications, SJCET, Palai Page 111

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

64 bytes from 74.125.53.105: icmp_seq=1 ttl=50 time=46.662 ms 64 bytes from 74.125.53.105: icmp_seq=2 ttl=50 time=52.202 ms 64 bytes from 74.125.53.105: icmp_seq=3 ttl=50 time=50.108 ms 64 bytes from 74.125.53.105: icmp_seq=4 ttl=50 time=51.690 ms

--- 74.125.53.105 ping statistics --5 packets transmitted, 5 packets received, 0% packet loss round-trip min/avg/max/stddev = 46.662/49.972/52.202/1.975 ms

Various options of ping command are listed in table 4.1

Table 4.6

-a -b

Make ping audible. Beep each time response is received. Ping a broadcast address. Stop after sending count ECHO_REQUEST packets. With deadline option, ping waits for count ECHO_REPLY packets, until the timeout expires. Show network addresses as numbers. ping normally displays addresses as host names. Quiet outputnothing is displayed except the summary lines at startup time and when finished. Specify the interval between successive transmissions. The default is one second.

-c count

-n

-q

-i

Dept. of Computer Science And Applications, SJCET, Palai Page 112

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

-t -w

Set the IP Time to Live to n seconds. Exit ping after n seconds.

You may get a "Destination Host Unreachable" message. There message is caused by your router or server knowing that the target IP address is part of a valid network, but is getting no response from the target server. There are a number of reasons for this:

If you are trying to ping a host on a directly connected network: 1. The client or server might be down, or disconnected for the network. 2. Your NIC might not have the correct duplex settings. 3. You might have the incorrect type of cable connecting your Linux box to the network. There are two basic types, straight through and crossover.

4. In the case of a wireless network, your SSID or encryption keys might be incorrect.

[root@linuxbox root ]# ping 192.168.1.101

PING 192.168.1.101 (192.168.1.101) from 192.168.1.100 : 56(84) bytes of data. 64 bytes from 192.168.1.101: icmp_seq=1 ttl=128 time=3.95 ms 64 bytes from 192.168.1.101: icmp_seq=2 ttl=128 time=7.07 ms 64 bytes from 192.168.1.101: icmp_seq=3 ttl=128 time=4.46 ms 64 bytes from 192.168.1.101: icmp_seq=4 ttl=128 time=4.31 ms

Dept. of Computer Science And Applications, SJCET, Palai Page 113

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

--- 192.168.1.101 ping statistics --4 packets transmitted, 4 received, 0% loss, time 3026ms rtt min/avg/max/mdev = 3.950/4.948/7.072/1.242 ms

[root@linuxbox root ]# ping 192.168.1.105

PING 192.168.1.105 (192.168.1.105) from 192.168.1.100 : 56(84) bytes of data. From 192.168.1.100 icmp_seq=1 Destination Host Unreachable From 192.168.1.100 icmp_seq=2 Destination Host Unreachable From 192.168.1.100 icmp_seq=3 Destination Host Unreachable From 192.168.1.100 icmp_seq=4 Destination Host Unreachable --- 192.168.1.105 ping statistics --8 packets transmitted, 0 received, +6 errors, 100% loss, time 7021ms, pipe 3

4.7 traceroute Another tool for network troubleshooting is the traceroute command. It gives a listing of all the router hops between your server and the target server. This helps you verify that routing over the networks in between is correct. The traceroute command works by sending a UDP packet destined to the target with a TTL of 0. The first router on the route recognizes that the TTL has already been exceeded and discards or drops the packet, but
Dept. of Computer Science And Applications, SJCET, Palai Page 114

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

also sends an ICMP time exceeded message back to the source. The traceroute program records the IP address of the router that sent the message and knows that that is the first hop on the path to the final destination. The traceroute program tries again, with a TTL of 1. The first hop, sees nothing wrong with the packet, decrements the TTL to 0 as expected, and forwards the packet to the second hop on the path. Router 2, sees the TTL of 0, drops the packet and replies with an ICMP time exceeded message. traceroute now knows the IP address of the second router. This continues around and around until the final destination is reached.

Example [root@linuxbox root ]# traceroute www.google.com traceroute to google.com (74.125.236.132), 30 hops max, 60 byte packets 1 220.224.141.129 (220.224.141.129) 89.174 ms 89.094 ms 89.054 ms 2 115.255.239.65 (115.255.239.65) 109.037 ms 108.994 ms 108.963 ms 3 124.124.251.245 (124.124.251.245) 108.937 ms 121.322 ms 121.300 ms 4 * 115.255.239.45 (115.255.239.45) 113.754 ms 113.692 ms 5 72.14.212.118 (72.14.212.118) 123.585 ms 123.558 ms 123.527 ms 6 72.14.232.202 (72.14.232.202) 123.499 ms 123.475 ms 143.523 ms 7 216.239.48.179 (216.239.48.179) 143.503 ms 95.106 ms 95.026 ms 8 bom03s02-in-f4.1e100.net (74.125.236.132) 104.954 ms 94.980 ms 104.989 ms

Each lines gives the details of interaction with each router encountered. So we see that traceroute not only gives the IP addresses of the intermediate routers but also three round trip times for that particular router as for each router the traceroute commands fires three packets.
Dept. of Computer Science And Applications, SJCET, Palai Page 115

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

The * field in output There are times when one could encounter an * in the output rather than a value. This depicts that the required field could not be fetched. The reason can be anything from reverse DNS lookup failure to packets not hitting the target router to packets getting lost on their way back. So we see that the reason could be many but for all these type of cases the traceroute utility provides an * in the output.

[root@linuxbox root ]# traceroute google.com traceroute to google.com (74.125.236.101), 30 hops max, 60 byte packets 1 *** 2 *** 3 *** 4 *** 5 *** . 26 * * * 27 * * * 28 * * * 29 * * * 30 * * * 4.8 File Transfer Protocol (FTP)

Dept. of Computer Science And Applications, SJCET, Palai Page 116

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

File Transfer Protocol (FTP) is a network protocol used to copy a file from one computer to another over the Internet or LAN. FTP follows a client-server architecture which utilizes separate control and data connections between the ftp client and server. The default port for ftp is 21. FTP is not an encrypted transmission, which means any data sent over it, including your username and password could be read by anyone who may intercept your transmission. If you need a more secure transmission, use SFTP instead of FTP.

Use the following syntax to connect to transfer files to and from a remote network ftp site. [biju@linuxbox biju ]$ ftp 172.16.48.16 Or [biju@linuxbox biju ]$ ftp <domain name>

It will ask for the login name and password. If the credentials are O.K, then it returns a ftp> prompt. Various ftp commands are used for transferring files from the remote system. To get the ftp help, type help at the ftp> prompt ftp> help

The ftp can be used to transfer files using browser also. If the browser is to be used, then type the following in the address bar. ftp://172.16.48.16 The files that have read permissions will be displayed in the browser window and can be downloaded to the local system.

Dept. of Computer Science And Applications, SJCET, Palai Page 117

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

In order to use sftp, you may simply type sftp instead of ftp.

4.9 NcFTP NcFTP is a user interface to the Internet standard File Transfer Protocol. This program allows a user to transfer files to and from a remote network site, and offers additional features that are not found in the standard interface, ftp. NcFTP utilities let system administers provide FTP flexibility and performance. NcFTP offers the ability to resume failed transfers and retries, which is very useful when transferring large files across the network or across networks that suffer from bottlenecks. NcFTP can output a status bar detailing the progress of the transfer (much like SCP). However, NcFTP does not support any encryption, which might be an issue for some installations. The program runs in one of three modes: visual mode, line mode, and colon mode. If your system is somewhat modern, the default mode should be visual mode. This is a full-screen interface that uses the curses library. With visual mode, you edit the program's settings with a nice screen interface instead of typing arcane commands. If you are not in visual mode, you will be using line mode for the interactive shell. This mode is a no-frills command-line interface that will look like the default ftp program's command shell. The third mode, colon mode, refers to the program's ability to do a quick retrieve of a file directly from your shell command line, without going into the program's own shell. This mode is useful for shell scripts.

The syntax is as follows $ ncftpput ftp-host-name /path/to/remote/dir /path/to/local/dir

$ ncftpput -options ftp-host-name /path/to/remote/dir /path/to/local/dir


Dept. of Computer Science And Applications, SJCET, Palai Page 118

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

Try the ncftpput client command as follows: $ ncftpput -R -v -u "username" mcalab.net/var/www/html /home/mca/test

Where,

-u "username" : Ftp server username -v : Verbose i.e. show upload progress -R : Recursive mode; copy whole directory trees. Mcalab.net : Remote ftp server (use FQDN or IP). /var/www/html : Remote ftp server directory where all files and subdirectories will be uploaded. /home/mca/test: Local directory (or list of files) to upload remote ftp server directory /var/www/html.

4.10 Mail Facilities The Linux provides email server programs such as sendmail, fetch mail, postfix..etc. The various client programs include pine, mutt, mail.etc.
Dept. of Computer Science And Applications, SJCET, Palai Page 119

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

Squirrel mail is a webmail program available in Linux. The following examples illustrate typical uses of the command mail for sending and receiving email.

[biju@linuxbox biju ]$ mail This command starts up the mail utility and prints a summary line for each email message currently in your mail box. There is now a new prompt (&), at which you can enter any of the mail commands. The output looks something like this:

Mail version 8.1.2 01/15/2011. Type ? for help. "/var/mail/biju": 2 messages 2 unread >U 1 liz@mcalab.net Sun Nov 11 15:31 17/500 test2 U 2 tresa@mcalab Sun Nov 11 15:34 17/500 test4 &

You can show the full content of a particular message by entering the message number. For example, the following command displays the content of the second message: &2 You can reply to this message by entering "r" and hitting the return key: &r This will display the automatically generated "To" and "Subject" fields of the message, and will allow you to type in your message. When you are finished you hit Ctrl-d to exit the editor. The system then gives you the option specify "cc" recipients. Hitting "return" will send the message off.
Dept. of Computer Science And Applications, SJCET, Palai Page 120

MODULE 4 MCA-503 Linux Internals

ADMN 2009-10

To send a message to a particular recipient you type "mail" followed by the email address of the recepient: & mail biju@gmail.com As in the case of "reply", this will display the automatically generated "To" and "Subject" fields of the message, and will allow you to type in and send your message. You can get a list of all the commands with: & list

4.10.1 Mutt Mutt is a small but very powerful text based program for reading electronic mail under Linux operating systems, including support for color terminals, MIME, and a threaded sorting mode. Mutt has an easy-to-use screen-based interface and an extensive set of features, such as MIME support. On most distributions, the Mutt manual is located in the /usr/doc directory under Mutt. To evoke mutt, you type mutt at the command prompt. It has the facility to read, write send attach facilities with various options.

Dept. of Computer Science And Applications, SJCET, Palai Page 121

Potrebbero piacerti anche