Chapter 22. Miscellaneous

Table of Contents
22.1. Scheduling tasks with cron
22.2. Hard disk parameters
22.3. Monitoring memory usage

22.1. Scheduling tasks with cron

Written by Murray Stokely.

Slackware Linux includes an implementation of the classic UNIX cron daemon that allows users to schedule tasks for execution at regular intervals. Each user can create, remove, or modify an individual crontab file. This crontab file specifies commands or scripts to be run at specified time intervals. Blank lines in the crontab or lines that begin with a hash ("#") are ignored.

Each entry in the crontab file must contain 6 fields separated by spaces. These fields are minute, hour, day, month, day of week, and command. Each of the first five fields may contain a time or the "*" wildcard to match all times for that field. For example, to have the date command run every day at 6:10 AM, the following entry could be used.

10 6 * * * date

A user crontab may be viewed with the crontab -l command. For a deeper introduction to the syntax of a crontab file, let us examine the default root crontab.

# crontab -l
# If you don't want the output of a cron job mailed to you, you have to direct
# any output to /dev/null.  We'll do this here since these jobs should run
# properly on a newly installed system, but if they don't the average newbie
# might get quite perplexed about getting strange mail every 5 minutes. :^)
# Run the hourly, daily, weekly, and monthly cron jobs.
# Jobs that need different timing may be entered into the crontab as before,
# but most really don't need greater granularity than this.  If the exact
# times of the hourly, daily, weekly, and monthly cron jobs do not suit your
# needs, feel free to adjust them.
# Run hourly cron jobs at 47 minutes after the hour:
47(1) *(2) *(3) *(4) *(5) /usr/bin/run-parts /etc/cron.hourly 1> /dev/null(6)
# Run daily cron jobs at 4:40 every day:
40 4 * * * /usr/bin/run-parts /etc/cron.daily 1> /dev/null
# Run weekly cron jobs at 4:30 on the first day of the week:
30 4 * * 0 /usr/bin/run-parts /etc/cron.weekly 1> /dev/null
# Run monthly cron jobs at 4:20 on the first day of the month:
20 4 1 * * /usr/bin/run-parts /etc/cron.monthly 1> /dev/null
The first field, 47, specifies that this job should occur at 47 minutes after the hour.
The second field, *, is a wildcard, so this job should occur every hour.
The third field, *, is a wildcard, so this job should occur every day.
The fourth field, *, is a wildcard, so this job should occur every month.
The fifth field, *, is a wildcard, so this job should occur every day of the week.
The sixth field, /usr/bin/run-parts /etc/cron.hourly 1> /dev/null, specifies the command that should be run at the time specification defined in the first five fields.

The default root crontab is setup to run scripts in /etc/cron.monthly on a monthly basis, the scripts in /etc/cron.weekly on a weekly basis, the scripts in /etc/cron.daily on a daily basis, and the scripts in /etc/cron.hourly on an hourly basis. For this reason it is not strictly necessary for an administrator to understand the inner workings of cron at all. With Slackware Linux, you can simply add a new script to one of the above directories to schedule a new periodic task. Indeed, perusing those directories will give you a good idea of the work that Slackware Linux does behind the scenes on a regular basis to keep things like the slocate database updated.

22.2. Hard disk parameters

Many modern disks offer various features for increasing disk performance and improving integrity. Many of these features can be tuned with the hdparm command. Be careful with changing disk settings with this utility, because some changes can damage data on your disk.

You can get an overview of the active settings for a disk by providing the device node of a disk as a parameter to hdparm:

# hdparm /dev/hda

 multcount    =  0 (off)
 IO_support   =  1 (32-bit)
 unmaskirq    =  1 (on)
 using_dma    =  1 (on)
 keepsettings =  0 (off)
 readonly     =  0 (off)
 readahead    = 256 (on)
 geometry     = 65535/16/63, sectors = 78165360, start = 0

A common cause for bad disk performance is that DMA was not automatically used by the kernel for a disk. DMA will speed up I/O throughput and offload CPU usage, by making it possible for the disk to directly transfer data from the disk to the system memory. If DMA is turned off, the overview of settings would shows this line:

using_dma    =  0 (off)

You can easily turn on DMA for this disk with the -d parameter of hdparm:

# hdparm -d 1 /dev/hda

 setting using_dma to 1 (on)
 using_dma    =  1 (on)

You can do this during every boot by adding the hdparm command to /etc/rc.d/rc.local.

The -i parameter of hdparm is also very useful, because it gives detailed information about a disk:

# hdparm -i /dev/hda

 Model=WDC WD400EB-00CPF0, FwRev=06.04G06, SerialNo=WD-WCAAT6022342
 Config={ HardSect NotMFM HdSw>15uSec SpinMotCtl Fixed DTR>5Mbs FmtGapReq }
 RawCHS=16383/16/63, TrkSize=57600, SectSize=600, ECCbytes=40
 BuffType=DualPortCache, BuffSize=2048kB, MaxMultSect=16, MultSect=off
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=78163247
 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes:  pio0 pio1 pio2 pio3 pio4 
 DMA modes:  mdma0 mdma1 mdma2 
 UDMA modes: udma0 udma1 udma2 udma3 udma4 *udma5 
 AdvancedPM=no WriteCache=enabled
 Drive conforms to: device does not report version: 

 * signifies the current active mode

22.3. Monitoring memory usage

In some situations it is handy to diagnose information about how memory is used. For example, on a badly performing server you may want to look whether RAM shortage is causing the system to swap pages, or maybe you are setting up a network service, and want to find the optimum caching parameters. Slackware Linux provides some tools that help you analyse how memory is used.

22.3.1. vmstat

vmstat is a command that can provide statistics about various parts of the virtual memory system. Without any extra parameters vmstat provides a summary of some relevant statistics:

# vmstat
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0  0      0 286804   7912  98632    0    0   198     9 1189   783  5  1 93  1

Since we are only looking at memory usage in this section, we will only have a look at the memory and swap fields.

  • swpd: The amount of virtual memory being used.

  • free: The amount of memory that is not used at the moment.

  • buff: The amount of memory used as buffers.

  • cache: The amount of memory used as cached.

  • si: The amount of memory that is swapped in from disk per second.

  • si: The amount of memory that is swapped to disk per second.

It is often useful to see how memory usage changes over time. You can add an interval as a parameter to vmstat, to run vmstat continuously, printing the current statistics. This interval is in seconds. So, if you want to get updated statistics every second, you can execute:

# vmstat 1
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 2  0      0 315132   8832  99324    0    0   189    10 1185   767  5  1 93  1
 1  0      0 304812   8832  99324    0    0     0     0 1222  6881 24  8 68  0
 0  0      0 299948   8836  99312    0    0     0     0 1171  1824 41  9 49  0

Additionally, you can tell vmstat how many times it should output these statistics (rather than doing this infinitely). For example, if you would like to print these statistics every two seconds, and five times in total, you could execute vmstat in the following manner:

# vmstat 2 5
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 2  0      0 300996   9172  99360    0    0   186    10 1184   756  5  1 93  1
 0  1      0 299012   9848  99368    0    0   336     0 1293  8167 20  8 21 51
 1  0      0 294788  11976  99368    0    0  1054     0 1341 12749 14 11  0 76
 2  0      0 289996  13916  99368    0    0   960   176 1320 17636 22 14  0 64
 2  0      0 284620  16112  99368    0    0  1086   426 1351 21217 25 18  0 58