Table of Contents

Environment variables

For a running process

There are a couple of alternatives that I know of, both have to be run as root:

SSH Equivalence

Every so often we get new servers and I setup SSH equivalence between them,
equally frequently I need to remind myself of the process.
The following is an example:

$ cd ~
  # Create the required directory and set it's permissions
  # Repeat these steps on all nodes
$ mkdir .ssh
$ chmod 755 .ssh
$ cd .ssh

  # Create private and public keys. Note that I don't use a passphrase
  # Repeat these two steps on all nodes
$ /usr/bin/ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/oracle/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/oracle/.ssh/id_dsa.
Your public key has been saved in /home/oracle/.ssh/id_dsa.pub.
The key fingerprint is:
c7:d9:65:78:ee:db:a6:80:7c:54:37:25:cd:9f:36:eb oracle@wg0048

$ /usr/bin/ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/oracle/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/oracle/.ssh/id_rsa.
Your public key has been saved in /home/oracle/.ssh/id_rsa.pub.
The key fingerprint is:
0f:eb:c6:80:c9:5c:dd:6f:ad:71:ff:f8:6d:de:3c:83 db2@wg0048

  # Remaining steps on first node only

  # Append the public keys to authorized_keys file
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

  # Append public keys from other node(s)
$ ssh oracle@dv0027 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
The authenticity of host 'dv0027 (10.156.134.87)' can't be established.
RSA key fingerprint is d0:14:2c:e1:d2:ef:ad:39:11:59:9d:ad:7b:ad:51:40.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.156.134.87' (RSA) to the list of known hosts.
oracle@dv0027's password:

$ ssh oracle@dv0027 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
oracle@dv0027's password:

  # Set permissions of authorized_keys
$ chmod 644 ~/.ssh/authorized_keys

  # Copy public keys file to other node(s)
$ scp ~/.ssh/authorized_keys dv0027:/home/oracle/.ssh
oracle@dv0027's password:

  # Should all be working
$ ssh dv0027 date
Wed Feb 16 07:58:32 EST 2011

Cron scheduling

We know that the first 5 fields of cron govern when the job runs, e.g.

  1. minute
  2. hour
  3. day of month
  4. month
  5. day of week

What we maybe weren't aware of is how these are combined to run a job -

A job will run:

  1. When the Minute, Hour and month match the current time
    and
  2. When EITHER the Day of Month AND/OR the Day of Week match the current day

So - a cron job scheduled like this:

00 12 18 09 Sat /home/oracle/bin/job.sh >/home/oracle/log/job.log 2>&1

Will run at 12:00 on the 18th of September AND every Saturday in September at 12:00

The moral of this particular story -

For one-off jobs - comment out the job after it has run
OR
Use at to schedule the job, e.g.

$ echo "/home/oracle/bin/job.sh >/home/oracle/log/job.log 2>&1" | at now + 1 minute

PS:
Changing either the Day of month or Day of week to “*” will prevent this behaviour.

sar

Identify sar file for a particular day

From the example below, the file to use for subsequent sar commands to look at data for Sept.12 would be /var/log/sa/sa12

$ ls -al /var/log/sa | grep "Sep 12"
-rw-r--r--  1 root root 322800 Sep 12 23:50 sa12
-rw-r--r--  1 root root 350628 Sep 12 23:53 sar12

Paging

$ sar -W -f /var/log/sa/sa12
Linux 2.6.18-194.el5 (el0054)         09/12/2010

12:00:01 AM  pswpin/s pswpout/s
12:10:01 AM      1.45      0.32
12:20:01 AM      1.53      0.24
12:30:01 AM      0.07      0.16
12:40:01 AM    148.65      1.15
12:50:02 AM     89.62      3.42
01:00:01 AM    314.33      1.02
01:10:01 AM      0.11      0.19
01:20:01 AM    132.83      0.04
01:30:01 AM     41.54      0.05
01:40:01 AM      0.10      0.07
...