Create function keys based shortcut to speeding up work at Linux command line part # 2

Posted on in Categories News last updated August 31, 2005

Under MS-Windows we all used hot function keys. Can we define hot keys under Linux? For example when I hit F1 key it should start top command or when I press F2 it should show the list of logged in users etc.
Linux comes with loadkeys utiluitity – its main purpose is to load the kernel keymap for the console. Using this utility you can modify the behavior of keys. For example when you hit F1 it will show you top command i.e. re-define keyboard action.

(A) Dump keyboard translation tables (get existing key combination on screen)
# dumpkeys

Better store it to file so that it can be modified and reloaded with loadkeys:
# dumpkeys /root/mykeys

(B) Forcing F1 key to run top command:

i) Open the file mykeys (as saved above by dumplkeys) in vi text editor:
# vi /root/mykeys

ii)Look for line string F1 = “33[[A” change it
string F1 = “33[[A”
string F1 = “top\n”

iii)Save the file

iv)Load the new keyboard translation tables :
# looadkeys /root/mykeys

v) Hit F1 key to see top command in action.

This way you can customize all your special key to automate task and speed up your work. You can even load custom shell script. See Speeding up work at Linux command line # part 1. Read man pages of
* loadkeys
* dumpkeys
* showkey ( displays to standard output (screen) either the scan codes, the keycode, or the character of each key pressed/released under Linux)

HP-UX networking related tools and commands

Posted on in Categories News last updated August 31, 2005

As my journey continues to exploring HP-UX I found couple of nice utilities and tools to configure and administrate HP-UX networking subsystem.


  • /etc/hosts – Hosts configuration file (resolve hosts and IPs)
  • /etc/rc.config.d/netconf – IP address, routeing address and hostname stored in this file


  • /etc/init.d/net start – Use to start, stop network service

HPUX Commands
(a) Display lan interface info:
# lanscan

(b) All in one lan configuration utility (lan0 is first Ethernet interface) to configure and view the system IP address:
# ifconfig lan0 – Display IP info such as IP address netmask etc.
# ifconfig lan0 up – Up network interface (allow traffic)
# ifconfig lan0 down – Down network interactive (deny traffc)
# ifconfig lan0 netmask up – Setup/change IP adddress

(c) Displaying host name
# hostname

(d) Arp administration (cache)
# arp -a

(e) Display routing table/info:
# netstat -nr

(f) Define new route:
# route add default 1

(g) HP’s LAN diagnostic tool
# lanadmin

(h) Test a remote host connectivity

(i) Setup various lan properties, dns client, NIS client configuration etc using GUI tool:
# sam
# set_parms

(j) Check dns connectivity:
$ nslookup

See also
How do I start hpux network service?
HP-UX: How Do I configure the new Lan card configuration?

xrandr: Linux Resize / Set The Screen Size Quickly Via Command Line Options

Posted on in Categories Debian Linux, Howto, Linux, Linux desktop, RedHat/Fedora Linux, Tips, Troubleshooting, Tuning, Ubuntu Linux, UNIX, X server last updated August 27, 2005

Generally, I need to switch my Gnome screen size to 800×600 to watch TV via TV-Tunner card as my card supports max 800×600 resolution. For rest of my work I prefer to use 1024×768 pixels. You can create a shortcuts on the desktop to resize screen quickly:

First taste of HP-UX system administration

Posted on in Categories News last updated August 26, 2005

Recently I had chance to play with HP-UX UNIX on HP hardware. To my surprise most of Linux command do work with HP-UX with some minor changes in syntax :). It has nifty tool called SAM (The System Administration Manager) is a GUI user interface for performing most routing administrative tasks without using command line admin utility. The SAM works under CDE (common desktop environment).

I’m gone administrate at least 3-4 HP-UX box for next couple of weeks before they are going to get new UNIX admin for growing data center. So I will have chance to get my hands on dirty with HP-UX. That means you will see couple of HP-UX related entries in this blog. As soon as these HP-UX box comes in our IDC, I was asked to add user accounts. To be frank I was bit frightened because I never worked on HP-UX. Here is what so far I have learned:

These are almost same as Linux user admin commands, here is quick summery:

Important files:

  • /etc/passwd – User account database file
  • /etc/group – Group database file
  • /etc/profile – System login script
  • ~/.profile – Users own login script
  • ~/.shrc OR ~/.kshrc OR ~/.cshrc – Users own shell startup script (these are executed always whenever users login)
  • /etc/skel/ – Default directory from which all files copied when new users created.

a) useradd – Create a new users

# useradd -m rocky

b) usermod – Modify user account

# usermod -G dbusers rocky

Modify secondary group membership of rocky
c) userdel – Remove user account, -r removes user foo home directory.

# userdel foo
# userdel -r foo

e)groupadd – Create a group

# groupadd dbusers

f) groupmod – Modify a group
Chantge the name of ftpusers to wwwproject

# groupmod -n wwwproject ftpusers

g) groupdel – Delete/remove the account group

# groupdel  wwwproject 

h) grpck – Check for syntax error in /etc/group file

i) pwck – Check for sysntax error in /etc/passwd file

j) passwd – Setup password and manage password restriction
Setup foo’s password

# passwd foo

Remove/delete password/null password

# passwd -d foo

Force to change password at next login

# passwd -f foo

Disable/Lock user account

# passwd -l foo

Unlock HP-UX user account by editing (using vi text editor) /etc/passwd file:

# vi /etc/passwd

Man pages are real help. These system are in our internal network; in coming days at least 2 system will go online for testing purpose so I may need to configure routing and other stuff (right now they are getting IP from our DHCP server).

So far so good. To be frank, I like the HP-UX , no problem to administrate it. May be in coming days I will see more surprises (ill keep my finger crossed).

Between I have noticed Sun had redesigned website. New sites looks quite cool and tries to improve corporate image.

Howto Reboot or halt Linux system in emergency

Posted on in Categories CentOS, Debian Linux, Gentoo Linux, Howto, Linux, Linux distribution, Networking, RedHat/Fedora Linux, Security, Suse Linux, Sys admin, Tips, Troubleshooting, Ubuntu Linux last updated August 25, 2005

Linux kernel includes magic system request keys. It was originally developed for kernel hackers. However, you can use this hack to reboot, shutdown or halt computer safely (remember safe reboot/shutdown == flush filesystem buffers and unmount file system and then reboot so that data loss can be avoided).

This is quite useful when Linux based system is not available after boot or after a X server crashed ( svgalib program crashes) or no display on screen. Sysrq key combo forces the kernel to respond it regardless of whatever else it is doing, unless it is completely locked up (dead).

Using further extension to iptables called ipt_sysrq (new iptables target), which allows you to do the same as the magic sysrq key on a keyboard does, but over the network. So if your network server is not responding you can still reboot it. Please note that Magic SysRq support need to be compiled in your kernel. You need to say “yes” to ‘Magic SysRq key (CONFIG_MAGIC_SYSRQ)’ when configuring the kernel. I’m assuming that you have Magic SysRq key’ support is compiled in your kernel.

Enable sysrq keys

By default it is not enabled on many Linux distributions. Add or modify following line (as soon as new Linux system installed) /etc/sysctl.conf:
# vi /etc/sysctl.conf
Append following config directive:
Save and close the file. Reload settings:
# sysctl -p

Save and close the file and reboot system to take effect

How do I use the magic SysRq keys in emergency?

You need to use following key combination in order to reboot/halt/sync file system etc:

The ‘SysRq’ key is also known as the ‘Print Screen’ key. COMMAND-KEY can be any one of the following (all keys need to hit simultaneously) :

  • ‘b’ : Will immediately reboot the system without syncing or unmounting your disks.
  • ‘o’ : Will shutdown your system off (if configured and supported).
  • ‘s’: Will attempt to sync all mounted filesystems.
  • ‘u’ : Will attempt to remount all mounted filesystems read-only.
  • ‘e’ : Send a SIGTERM to all processes, except for init.
  • ‘h’: Show help, indeed this the one you need to remember.

So whey you need to tell your Linux computer to reboot or when your X server is crashed or you don’t see anything going across the screen then just press:

ALT+SysRQ+s : (Press and hold down ALT, then SysRQ (Print Screen) key and press ‘s’) -Will try to syn all mounted system

ALT+SysRQ+r : (Press and hold down ALT, then SysRQ (Print Screen) key and press ‘r’) -Will reboot the system.

If you wish to shutdown the system instead of reboot then press following key combination:

ipt_sysrq is a new iptables target that allows you to do the same as the magic sysrq key on a keyboard does, but over the network. Sometimes a remote server hangs and only responds to icmp echo request (ping). Every administrator of such machine is very unhappy because (s)he must go there and press the reset button. It takes a long time and it’s inconvenient. So use the Network Magic SysRq and you will be able to do more than just pressing a reset button. You can remotely sync disks, remount them read-only, then do a reboot. And everything comfortably and only in a few seconds. Please see Marek Zelem page to enableIP Tables network magic SysRq function.

For more information read official Documentation for sysrq.c version 1.15 stored in /usr/src/linux/Documentation/sysrq.txt and read man page of sysctl, sysctl.conf.

How to: Compile Linux kernel modules

Posted on in Categories CentOS, Debian Linux, Gentoo Linux, GNU/Open source, Howto, Linux, RedHat/Fedora Linux, Tips, Ubuntu Linux last updated August 22, 2005

This is one the essential and important task. Many time we upgrade our kernel and some precompiled drivers won’t work with Linux. Especially if you have weird hardware; then vendor may send you driver code aka C files to compile. Or even you can write your own Linux kernel driver. Compiling kernel driver is easy. Kernel 2.6.xx makes it even much more easier. Following steps are required to compile driver as module:

1) You need running kernel source code; if you don’t have a source code download it from Untar kernel source code (tar ball) in /usr/src using tar command:
$ tar -zxvf kernel* -C /usr/src

To be frank kernel headers are more than sufficient to compile kernel modules / drivers. See how to install kernel headers under Debian / Ubuntu Linux or RHEL / CentOS / Fedora Linux.

2) Next go to your kernel module source code directory and simply create the Makefile file as follows (assuming your kernel module name is foo):
$ vi Makefile

3) Add following text to it:

obj-m = foo.o
KVERSION = $(shell uname -r)
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

4) Compile module using make command (module build can be done by any user) :
$ make
It will finally creates the foo.ko module in current directory. You can see all actual compile command stored in .foo* files in same directory.

5) Once module compiled successfully, load it using insmod or modprobe command. You need to be root user or privileged user to run insmod:
# insmod foo.ko

Example: hello.c module

1) hello.c C source code. Copy following code and save to hello.c
$ mkdir demo; cd demo
$ vi hello.c

2)Add following c source code to it:

#include <linux/module.h>       /* Needed by all modules */
#include <linux/kernel.h>       /* Needed for KERN_INFO */
#include <linux/init.h>         /* Needed for the macros */

static int __init hello_start(void)
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;

static void __exit hello_end(void)
printk(KERN_INFO "Goodbye Mr.\n");


This is an example modified from original source for demonstration purpose.

3) Save the file. Create new Makefile as follows:
$ vi Makefile
Append following make commands:

obj-m = hello.o
KVERSION = $(shell uname -r)
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
        make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

4) Save and close the file.

5) Compile hello.c module:
$ make

6) Become a root user (use su or sudo) and load the module:
$ su -
# insmod hello.ko

Note you can see message on screen if you are logged in as root under run level 3.

7) Verify that module loaded:
# lsmod | less

8) See message in /var/log/message file:
# tail -f /var/log/message

9) Unload the module:
# rmmod hello

10) Load module when Linux system comes up. File /etc/modules use to load kernel boot time. This file should contain the names of kernel modules that are to be loaded at boot time, one per line. First copy your module to /lib/modules/$(uname -r)/kernel/drivers. Following are suggested steps:

(a) Create directory for hello module:
# mkdir -p /lib/modules/$(uname -r)/kernel/drivers/hello
(b) Copy module:
# cp hello.ko /lib/modules/$(uname -r)/kernel/drivers/hello/
(c) Edit /etc/modules file under Debian Linux:
# vi /etc/modules
(d) Add following line to it:
(e) Reboot to see changes. Use lsmod or dmesg command to verify module loaded or not.
# cat /proc/modules
# lsmod | less

See also:

  • Read man pages of lsmod, rmmod, modprobe, modules
  • Documentation located in your kernel source directory (for example /usr/src/linux-2.6.xx.xx/Documentation/) and README file located under kernel source code tree /usr/src/linux-2.6.xx.xx/README
  • Read tutorial online.

Linux MySQL server monitoring

Posted on in Categories News last updated August 17, 2005

Some time due to high load MySQL server gets killed by OS. So we need to make sure that whenever it gets killed restart the mysql server and send an email notification along with status of mysql server. This is simple and yet effective script.

Please see the monitor_mysql.bash script (download link at the end of script)

Customizing the script. Open the script in text editor such as vi, you can customize following 5 directives (read as variable):

1) MUSER=”root”
Change this if your mysql admin user is not root.

Setup password, this the ONLY one you need to setup.

Setup hostname if it is not localhost

4) MSTART=”/etc/init.d/mysql start”
This is default on Debain Linux, you need to setup this according to your UNIX/Linux/BSD OS.

5) EMAILID=”[email protected]
Set Email ID to send notification.

Once all done save the file and install script as cron job. For example run this script every minute
* * * * * /path/to/monitor_mysql.bash

Linux Apache setting Perl CGI Script Limits

Posted on in Categories News last updated August 17, 2005

Usually Perl and/or CGI scripts can go wild and eat up ALL system resources: this is dangerous stuff can be controlled by three directives. Apache comes with three directives to place limits on the the amount of CPU, memory and processes the server can use.
i) RLimitCPU – restrict the strain of CPU usage.
Example: RLimitCPU 10 20

ii) RLimitNPROC – restrict the number of the processes run simultaneously.
Example: RLimitMEM 200000 200000

iii) RLimitMEM – restrict the memory used by processes run on the server.
Example RLimitNPROC 3 5

You can above three three directives in vhost or main server configuration. First value to each of above example is soft (minimum) limit and second value is hard (maximum) limit which cannot be crossed by any process. Here is more practical and realistic example to be used in mass hosting server (open your httpd.conf file and add following three directives):

A) Set Maximum 100 CPU second to be used by a process so Perl process will die if it is continue for more than 100 seconds i.e. Perl scripts may run for no more than 100 seconds. Scripts running longer than 100 seconds will be stopped automatically by the system/Apache.
RLimitCPU 100 100

B) Set Maximum of 25 processes at any one time
RLimitNPROC 25 25

C) Allow 10 MB to be used per-process
RLimitMEM 10000000 10000000

Once added to httpd.conf file restart the apache process. Please note that you must experiment to see how low you can set these values as per your setup. You can also use ulimit to get and set user limits. Under Debian GNU/Linux www-data is right user to setup these limits. Read man/help page of ulimit and pam configuration for more information. Please see official apache website for Rlimit directives.

(Check out all of our posts on Perl)

Restore Debian Linux Grub boot loader

Posted on in Categories Debian Linux, Tips, Troubleshooting, Ubuntu Linux last updated August 15, 2005

Recently my hard disk went bad (some bad sectors developed), my boot.ini (Windows XP boot file) corrupted. I was using NT boot loader to load Linux. So I need to repair the Grub i.e. restore Grub in master boot record (MBR).

Today is national holiday (I-DAY) and I wanna watch TV. Problem is neither I can boot to Linux nor using XP. So I just took my Debian GNU/Linux DVD and booting started when I had presented installation option (after networking dialog prompt) :
1) Press ALT+F2 (or ALT+CTRL+F2) to get shell prompt
2) Then get the partition tables for the devices using fdisk command:
# fdisk -l

3)When you type fdisk -l, you should see your partition name: /dev/scsi/host0/bus0/target0/lun0/part1 (for IDE disk it display same device file in IDE directory)

4)Once you identified your device file, mount disk using mount command:
# mkdir /mydisk
# mount /dev/scsi/host0/bus0/target0/lun0/part1 /mydisk

5) Next use chroot command to start interactive shell with special root directory i.e. /mydisk will act as root directory.
# chroot /mydisk

6)Use grub-install command to reinstall grub (SCSI disk):
# grub-install /dev/sda

If you have IDE device following command :
# grub-install /dev/hda

Again replace /dev/hda and /dev/sda with your actual device names.

7)Type exit and reboot the system. You should see your GRUB and Linux again.
# exit

Other choice was to use Linux Live CD (e.g. Mepis) and do the above procedure. Well, I could have used the Mepis to watch TV but I had some data and emails in Tunderbird so I opted to restore the Grub; watched TV, took backup of emails and now I will put new 120 GiB hard disk tomorrow 😀