≡ Menu

Gentoo Linux

Lighttpd / Apache : Run Xcache in Chrooted Jail

Recently I wrote about installing and running Xcache under Red hat enterprise Linux and CentOS Linux. By default Xcache use /dev/zero for caching. All you have to do is create /dev/zero in chrooted jail. Type the following command (assuming that your jail is located at /lighttpd.jail directory):
# mkdir -p /lighttpd.jail/dev
# mknod -m 666 /lighttpd.jail/dev/zero c 1 5

Just restart your web server and xcache should work under chrooted lighttpd web server.

fping is one my favorite network profiling / scripting tool. It uses the Internet Control Message Protocol (ICMP) echo request to determine if a target host is responding or not.

Unlike ping , fping is meant to be used in scripts, so its output is designed to be easy to parse.

You can easily write perl / shell script to check a list of hosts and send mail if any are unreachable.

fping command example

Just type the following command to see if we can reach to router:
$ fping router
Output:

router is alive

You can read list of targets (hosts / servers) from a file. The -f option can only be used by the root user. Regular users should pipe in the file via
I/O redirectors (stdin). For example read all host names from ~/.ping.conf file
$ fping < ~/.ping.conf

You can also netmask to ping the entire network i.e generate a target list from a supplied IP netmask. For example, ping the class C 192.168.1.x:
$ fping -g 192.168.1.0/24
or
$ fping -g 192.168.1.0 192.168.1.255

Sample shell script to send email if host is down

#!/bin/bash
HOSTS="router sun printer laptop sony-laptop xbox backup-server"
DLIST=""
for h in $HOSTS
do
  fping -u $h >& /dev/null
  if [ $? -ne 0 ]; then
          echo ${h} host is down send email
          # mail -s "Host ${h} down" admin@you.com </dev/null
  fi
done

Another good example is when you want to perform an action only on hosts that are currently reachable.

#!/usr/bin/perl
$myHosts = ‘cat /etc/hosts.backup | fping -a‘;
foreach $host (split(/\n/,$myHosts)) {
        # take action or call other function
}

You can find the memory used by a program (process) by looking into /proc directory or using standard command such as ps or top. However, you must calculate all memory usage by hand i.e. add Shared Memory + mapped file + total virtual memory size of the process + Resident Set Size + non-swapped physical memory used by process.

So how do you find the memory used by a process or program under Linux? [click to continue…]

How to: Linux configure fingerprint reader

Recently I was looking information about getting the integrated fingerprint reader to work under Linux. I found this site. It describes the process of getting the integrated fingerprint reader to work under Linux, using bioapi and binary-only drivers. It is based on experiences in Ubuntu on a IBM Thinkpad T43. The same works on Fedora Core 4 and 5, RHEL4, SuSE 9.3, SuSE 10, and Gentoo.

=> How to enable the fingerprint reader

Reboot Linux box after a kernel panic

If you want the server to get rebooted automatically after kernel hit by a pain error message, try adding panic=N to /etc/sysctl.conf file.

It specify kernel behavior on panic. By default, the kernel will not reboot after a panic, but this option will cause a kernel reboot after N seconds. For example following boot parameter will force to reboot Linux after 10 seconds.
[click to continue…]

Linux Save the output of a command in a logfile

You can use logsave command to save the output of a command in a logfile. General syntax is as follows:
logsave /path/to/logfile command-name argument(s)

The logsave program will execute command-name with the specified argument(s), and save a copy of its output to logfile. If the containing directory for logfile does not exist, logsave will accumulate the output in memory until it can be written out. A copy of the output will also be written to standard output. If command-name is a single hyphen (-), then instead of executing a program, logsave will take its input from standard input and save it in logfile

logsave is useful for saving the output of initial boot scripts until the /var partition is mounted, so the output can be written to /var/log. For example, save output of ls command to output.log file:
logsave /tmp/output.txt ls
For example run lftp and save remote server file list to /tmp/filelist.txt for other scripts:
logsave /tmp/filelist.txt 'lftp -u -e "cd pub;ls;quit;" admin,mypassword ftp.nixcraft.in '

I've already outlined the detailed steps for migrating users, home directories and email to a new Linux server. I received a couple of emails asking about migrating printer configuration. From my mail bag:

Is it possible to migrate the printer configuration from one machine to another, just like user migration?

Yes, it is possible since Linux uses CUPS i.e. the common unix printing system. It is a modular printing system for Unix-like computer operating systems that allows a computer to act as a print server. A computer running CUPS is a host that can accept print jobs from client computers, process them, and send them to the appropriate printer.

Migrate Linux Printer Configuration

CUPS stores its configuration at /etc/cups directory, so all you have to do is copy /etc/cups to a new computer. Open terminal and type the commands on old Linux computer:
# tar -cvzf /tmp/cups-$(hostname).tar.gz /etc/cups
Copy /tmp/cups* to new system using SCP or use USB pen driver:
# scp /tmp/cups* new.linux.server.com:/tmp

Now login to new system and type the following commands:
# mv /etc/cups /etc/cups.backup
# cd /
# tar -zcvf /tmp/cups*

Finally, restart the cups service:
# /etc/init.d/cupsys restart