Set up CUPS to print to a network printer via the command line

How to install CUPS, foomatic, gutenprint, etc. will depend on the OS, as will daemon starting.

# yum groupinstall "Print Server" "Printing Client"
# service cups start && chkconfig cups on

The rest is pretty universal.

The lpinfo line is simply to find the name of the model script. You may need to get creative with what you search for.

# lpinfo -m | grep "printer model"
# lpadmin -p PRINTERNAME -m MODELSCRIPT -v socket://IPADDRESS
# cupsenable PRINTERNAME
# cupsaccept PRINTERNAME

Update grub2 settings

# vim /etc/sysconfig/grub
# grub2-mkconfig -o /boot/grub2/grub.cfg

Adding Package Architecture to an RPM Package Listing

rpm -q by default doesn’t show the architecture of the packages, which can result in annoying things like this:

# rpm -q glibc
glibc-2.5-81
glibc-2.5-81

To fix this, use the --qf "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" option.

# rpm -q --qf "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" glibc
glibc-2.5-81.x86_64
glibc-2.5-81.i686

Turn off the monitor in command line mode (runlevel 3) in RHEL

In runlevel 3, RHEL (most Linuxes, probably) only blanks the monitor after so much inactivity, it doesn’t tell the monitor to actually turn off. This has annoyed me for years, but I just found a command to turn off and on the monitor:

# /usr/sbin/vbetool dpms [off|on]

I’ve haven’t rigged it to be triggered by console activity yet, but at least I can manually turn off and on the monitor through software now.

Find server model and serial number in Linux/RHEL

Ever needed to know the exact model or serial number of a Linux machine but only have access to the command line?

# dmidecode | egrep -i "product name|serial number"
        Product Name: ProLiant DL360 G7
        Serial Number: USE000A11M
        Serial Number: USE000A11M
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: Not Specified
        Serial Number: 57QXF00000D9D1
        Serial Number: 57QXF00000D9B2

A lot of the individual hardware components have serial numbers (or, could have serial numbers), but the first two identical ones are the actual system serial number. On this particular machine the two serial numbers listed at the end seem to be for the power supplies.

Update – September 09, 2011 at 09:31:
Even better:

# dmidecode -t system
# dmidecode 2.9
SMBIOS 2.6 present.

Handle 0x0100, DMI type 1, 27 bytes
System Information
        Manufacturer: HP
        Product Name: ProLiant DL360 G7
        Version: Not Specified
        Serial Number: USE000A11M
        UUID: 30000000-3000-5000-4000-300000000000
        Wake-up Type: Power Switch
        SKU Number: 579237-B21
        Family: ProLiant

Handle 0x2000, DMI type 32, 11 bytes
System Boot Information
        Status: No errors detected

RHEL 5 ethtool reports no link even though the link light is lit

I had an issue today setting up a new machine (HP DL380 G7, RHEL 5.5 x86_64) where ethtool wasn’t reporting a link on any of the NICs despite the actual physical link lights being lit up.

# ethtool eth1
Settings for eth1:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised auto-negotiation: Yes
        Speed: Unknown!
        Duplex: Half
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: g
        Wake-on: d
        Link detected: no

After a fair amount of hair pulling, I finally got it reporting correctly by setting the NICs to DHCP and trying to up them. Even though there was no DHCP server, just trying to up the interfaces got ethtool reporting correctly.

# cat /etc/sysconfig/network-scripts/ifcfg-eth1
# Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth1
BOOTPROTO=dhcp
HWADDR=<something>
ONBOOT=no
HOTPLUG=no
TYPE=Ethernet

# ifup eth1

Determining IP information for eth1... failed.

# ethtool eth1
Settings for eth1:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: g
        Wake-on: d
        Link detected: yes

Shrink ext3 Filesystem

Assume we have an ext3 filesystem on an LVM volume that is just way too big.

$ df -hlP /backups/
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-service_backup   99G   15G   79G  16% /backups

A 100 GB filesystem for 15 GB of data? That is way too big! Let’s shrink that down and reclaim some of that wasted space.

$ sudo /sbin/resize2fs -p /dev/VolGroup00/service_backup 25G
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/service_backup is mounted on /backups; on-line resizing required
On-line shrinking from 26214400 to 6553600 not supported.

Can’t shrink a mounted filesystem. No problem.

$ sudo umount /backups

$ sudo /sbin/resize2fs -p /dev/VolGroup00/service_backup 25G
resize2fs 1.39 (29-May-2006)
Please run 'e2fsck -f /dev/VolGroup00/service_backup' first.

Now I have to fsck? Ok, fine.

$ sudo e2fsck -f /dev/VolGroup00/service_backup
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/VolGroup00/service_backup: 37/13107200 files (5.4% non-contiguous), 4309966/26214400 blocks

$ sudo /sbin/resize2fs -p /dev/VolGroup00/service_backup 25G
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/VolGroup00/service_backup to 6553600 (4k) blocks.
Begin pass 2 (max = 2562078)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 800)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 8)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/VolGroup00/service_backup is now 6553600 blocks long.

Ah, there we go. Let’s make sure we didn’t screw anything up.

$ sudo e2fsck -f /dev/VolGroup00/service_backup
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/VolGroup00/service_backup: 37/3276800 files (5.4% non-contiguous), 3997466/6553600 blocks

Good, no problems found. Now that the filesystem is right-sized, next we have to shrink the logical volume.

$ sudo lvresize -L 25G /dev/VolGroup00/service_backup
  WARNING: Reducing active logical volume to 25.00 GB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce service_backup? [y/n]: y
  Reducing logical volume service_backup to 25.00 GB
  Logical volume service_backup successfully resized

And, just because I’m paranoid, let’s fsck one more time.

$ sudo e2fsck -f /dev/VolGroup00/service_backup
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/VolGroup00/service_backup: 37/3276800 files (5.4% non-contiguous), 3997466/6553600 blocks

Just need to remount the filesystem and we’re done!

$ sudo mount /backups

$ df -hlP /backups/
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-service_backup   25G   15G  8.6G  64% /backups

Ta-da!