It is a good practice to schedule certain routine tasks to run automatically. For example, you may want to remove old core files once a week, summarize accounting data daily and rotate system log files monthly.
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
crond and crontab: Schedule Routine Tasks
Using crontab, you can submit a list of commands in a format that can be read and executed by crond. Working as Superuser, you can put commands in one of the /etc/cron.* directories to be run at intervals specified by the directory name, such as cron.daily.
When SELinux is set to use a targeted policy, it protects the cron daemon. You can disable this protection if necessary.
cron stops for no one; try anacron
Tip: The crond daemon assumes the system is always running. A similar utility, anacron, does not make that assumption and is well suited to portable and home computers that are frequently turned off. The anacron utility takes its instructions from the /etc/anacrontab file unless you specify otherwise.
at: Runs Occasional Tasks
Like the cron utility, at allows you to run a job sometime in the future. Unlike cron, at runs a job only once. For instance, you can schedule an at job that will reboot the system at 3 a.m. when all users are probably logged off:
# at 3am
at> CONTROL-D <EOT>
job 1 at 2006-02-01 03:00
It is also possible to run an at job from within an at job. For instance, an at job might check for new patches every 18 days, something that would be more difficult with cron.
Many utilities report on one thing or another. The who, finger, ls, ps, and other utilities generate simple end-user reports. In some cases, these reports can help with system administration.
This section describes utilities that generate more in-depth reports that can usually provide more assistance with system administration tasks. Linux has many other report utilities, including (from the sysstat package) sar (system activity report), iostat (input/output and CPU statistics), and mpstat (processor statistics); (from the net-tools package) netstat (network report); and (from the nfsutils package) nfsstat (NFS statistics).
vmstat: Reports Virtual Memory Statistics
The vmstat utility (procps package) generates virtual memory information along with (limited) disk and CPU activity data. The following example shows virtual memory statistics in 3-second intervals for seven iterations (from the arguments 3 7). The first line covers the time since the system was last booted. The rest of the lines cover the period since the previous line.
Table 16-2: vmstat column heads
|r Number of waiting, runnable processes|
|b Number of blocked processes (in uninterruptable sleep)|
|memory||Memory information in kilobytes|
|swpd Used virtual memory|
|free Idle memory|
|buff Memory used as buffers|
|cache Memory used as cache|
|swap||System paging activity in kilobytes per second|
|si Memory swapped in from disk|
|so Memory swapped out to disk|
|io||System I/O activity in blocks per second|
|si Memory swapped in from disk|
|bi Blocks received from a block device|
|bo Blocks sent to a block device|
|system||Values are per second|
|cs Context switches|
|cpu||Percentage of total CPU time spent in each of these states|
|us User (nonkernel)|
|sy System (kernel)|
|wa Waiting for I/O|
top: Lists Processes Using the Most ResourcesThe top utility is a useful supplement to ps. At its simplest, top displays system information at the top and the most CPU-intensive processes below the system information. The top utility updates itself periodically; type q to quit. Although you can use command-line options, the interactive commands are often more helpful.
Table 16-3 top: interactive commands
|F||Specify a sort field.|
|h or ?||Displays a Help screen.|
|k||Prompts for a PID number and type of signal and sends the process that signal. Defaults to signal 15 (SIGTERM); specify 9 (SIGKILL) only when 15 does not work.|
|M||Sorts processes by memory usage.|
|O||Specify a sort field.|
|P||Sorts processes by CPU usage (default).|
|s||Prompts for time between updates in seconds. Use 0 for continuous updates.|
|SPACE||Updates the display immediately|
|T||Sorts tasks by time.|
|W||Writes a startup file named ~/.toprc so that next time you start top, it uses the same parameters it is currently using.|
parted: Reports on and Partitions a Hard Disk
The parted (partition editor) utility reports on and manipulates hard disk partitions. The following example shows how to use parted from the command line. It uses the print command to display information about the partitions on the /dev/sda drive:
Figure 16-3 depicts the partitions shown in this example. The first line that parted displays specifies the device being reported on (/dev/sda) and its size (165 GB). The print command displays the following columns:
- Number—The minor device number of the device holding the partition. This number is the same as the last number in the device name. In the example, 5 corresponds to /dev/sda5.
- Start—The location on the disk where the partition starts. The parted utility specifies a location on the disk as the distance in bytes from the beginning of the disk. Thus partition 3 starts 12 GB from the beginning of the disk.
- End—The location on the disk where the partition stops. Although partition 2 ends 12 GB from the beginning of the disk and partition 3 starts at the same location, parted takes care that the partitions do not overlap at this single byte.
- Size—The size of the partition in kilobytes (KB), megabytes (MB), or gigabytes (GB).
- Type—The partition type: primary, extended, or logical. See Figure 16-3 for information on partition types.
- File system—The filesystem type: ext2, ext3, fat32, linux-swap, and so on.
- Flags—The flags that are turned on for the partition, including boot, raid, and lvm. In the example, partition 1 is bootable.
Figure 16-3: The primary and extended partitions from the example
In the preceding example, partition 4 defines an extended partition that includes 143 GB of the 165-GB disk (see Figure 16-3). You cannot make changes to an extended partition without affecting all logical partitions within it.
In addition to reporting on the layout and size of a hard disk, you can use parted interactively to modify the disk layout. Be extremely careful when using parted in this manner, and always back up the system before you work with this utility. Changing the partition information—the partition table—on a disk can destroy the information on the disk.
parted can destroy everything
Be as careful with parted as you would be with a utility that formats a hard disk. Changes you make with parted can easily result in the loss of large amounts of data. If you are using parted and have any question about what you are doing, quit with a q command before making any changes. Once you give parted a command, it immediately makes the change you requested.
To partition a disk, give the command parted followed by the name of the device you want to work with. In the following example, after starting parted, the user gives a help (or just h) command, which displays a list of parted commands:
In response to the (parted) prompt, you can give the command help followed by the name of the command you want more information about. When you give a print? (or just p) command, parted displays current partition information, just as a print command on the command line does.
The parted utility will not allow you to set up overlapping partitions, except for logical partitions that overlap the extended partition that contains them. Similarly it will not allow you to create a partition that starts at the very beginning of the disk (cylinder 0). Both of these situations can cause loss of data.
Following are guidelines to remember when defining a partition table for a disk:
- Do not delete or modify the partition that defines the extended partition unless you are willing to lose all data on all logical partitions within the extended partition.
- If you put /boot on a separate partition, it is a good idea to put it at the beginning of the drive (partition 1) so there is no issue of Linux having to boot from a partition located too far into the drive. When you can afford the disk space, it is desirable to put each major filesystem on a separate partition. Many people choose to combine / (root), /var, and /usr into a single partition, which generally results in less wasted space but can, on rare occasions, cause problems.
- Although parted can create some types of filesystems, it is typically easiest to use this utility to create partitions and then use mkfs and mkswap to create filesystems on the partitions.
The following sequence of commands defines a 300-MB, bootable, Linux partition as partition 1 on a clean disk:
When you specify a size within parted, you can use a suffix of k (kilobytes), m (megabytes), or g (gigabytes). After creating a partition, give a print command to see where the partition ends. Perform this task before you define the next contiguous partition to make sure you do not waste space. After setting up all the partitions, exit from parted with a quit command.
Next make a filesystem (mkfs) on each partition that is to hold a filesystem (not swap). Make all partitions, except swap and /boot, of type ext3, unless you have a reason to do otherwise. Make the /boot partition of type ext2. Use mkswap to set up a swap area on a partition. You can use e2label to label partitions.
Keeping Users Informed
One of your primary responsibilities as system administrator is communicating with system users. You need to make announcements, such as when the system will be down for maintenance, when a class on some new software will be held and how users can access the new system printer. You can even start to fill the role of a small local newspaper, letting users know about new employees, births, the company picnic and so on.
Different communications have different priorities. For example, information about the company picnic in two months is not as time-sensitive as the fact that you are bringing the system down in five minutes. To meet these differing needs, Linux provides different ways of communicating. All of these methods are generally available to everyone, except for the message of the day, which is typically reserved for Superuser.The most common methods are described and contrasted in the following list.:
Use the write utility to communicate with a user who is logged in on the local system. You might use it, for example, to ask a user to stop running a program that is bogging down the system. The user might reply that he will be done in three minutes. Users can also use write to ask the system administrator to mount a tape or restore a file. GNOME opens a new window when it receives a message.
Wall: The wall (write all) utility effectively communicates immediately with all users who are logged in. It works similarly to write, except that users cannot use wall to write back to only you. Use wall when you are about to bring the system down or are in another crisis situation. Users who are not logged in will not get the message.
Use wall while you are Superuser only in a crisis situation. It interrupts anything anyone is doing.
Email: Email is useful for communicating less urgent information to one or more systems and/or remote users. When you send mail, you have to be willing to wait for each user to read it. The email utilities are useful for reminding users that they are forgetting to log out, their bills are past due, or they are using too much disk space.
Users can easily make permanent records of messages they receive via email, as opposed to messages received via write, so they can keep track of important details. It would be appropriate to use email to inform users about a new, complex procedure, so each user could keep a copy of the information for reference.
Message of the day:Users see the message of the day each time they log in in a textual environment. You can edit the /etc/motd file to change this message as necessary. The message of the day can alert users to upcoming periodic maintenance, new system features or a change in procedures.
Enabling User Manager in Red Hat Enterprise Linux
Choosing between Red Hat Enterprise Linux backup utilities
Using hard disk partitions to ease Linux tasks
This excerpt is from Mark Sobell's A Practical Guide to Fedora and Red Hat Enterprise Linux (5th Edition), published by Prentice Hall Professional. For more information, visit: www.informit.com/title/0137060882.