Archive for the ‘Tips and Tricks’ Category

Quick backups with ssh and gzip

Wednesday, October 20th, 2004

As a SysAdmin I sometimes need to make quick backups of a filesystem to a remote machine. Unix provides easy and quick ways to do this task.

The following command line uses dd – destroy disk command ;-) – to copy the content of /dev/hda11 and send the output to gzip and copy the resulting compressed file to the remote machine through ssh. The syntax is as follows:

dd if=/dev/hda11 | gzip | ssh user@remote_server dd of=/dest/path/hda11.gz

Note that /dev/hda11 should not be mounted (not accessed while backing up).

To restore the backed up filesystem do the following:

dd if=hda11.gz | gzip -d | ssh user@remote_host dd of=/dev/hda11

And your done! Quick and dirty backup for you.

grub: how to save current menu entry as default

Friday, September 3rd, 2004

If you have many grub menu options, grub can boot the previously booted option

default saved
timeout 15

title Gentoo(2.4)
root(hd0,0)
kernel /boot/bzImage-2.4 root=/dev/hda5
savedefault

title Gentoo(2.6) Qos
root(hd0,0)
kernel /boot/bzImage-2.4 root=/dev/hda5
savedefault

title Gentoo(2.6)
root(hd0,0)
kernel /boot/bzImage-2.6 root=/dev/hda5

Hiding boot time messages

Thursday, September 2nd, 2004

If you want to hide linux boot time messages or store them to a specific location then you could edit the /etc/inittab file and change it as follows:

rc::bootwait:/sbin/rc boot > /dev/null
l0:0:wait:/sbin/rc shutdown > /dev/null
l1:S1:wait:/sbin/rc single > /dev/null
l2:2:wait:/sbin/rc nonetwork > /dev/null
l3:3:wait:/sbin/rc default > /var/log/rl3
…..

Note that this example is taken from Gentoo Linux.

Processes and grep, the pgrep command

Thursday, August 19th, 2004

The pgrep command looks at the active processes on your system and displays information matching the criteria you specified.

Let’s see some sample usage.

List all the processes owned by root as long as process names:

pgrep -l -u root

In the same way list all the processes owned by snort and apache users and use “, ” (comma+white space) as field delimiter:

pgrep -l -u snort,apache -d”, “

List the processes whose controlling terminal is pts/0:

pgrep -l -t pts/0

List the processes whose controlling terminal is NOT pts/0:

pgrep -l -t pts/0 -v

References:

Starting squid with a clean cache

Friday, July 30th, 2004

Squid is an open source web proxy cache designed to run on Unix machines. Squid caches repeated requests thus increasing performance. But in some situations you will want to start Squid with an entirely clean cache. This tip will show you how.

First of all stop Squid and then…

echo ” ” > /path/to/squid/caches/swap.state

Now restart Squid and your done!

Note that you should repeat the above for every directory defined in the cache_dir option within squid.conf.

Debugging Shell scripts

Monday, May 31st, 2004

You can set your shell script excution verbose mode either by adding line set -vx at the begining of script or sh -x script_name.

#!/bin/sh
set -vx
date

Target architecture of a binary file

Friday, May 28th, 2004

If you want to know the targeted architecture of an executable file you can use the Gnu C Compiler, gcc.

The dumpfile debugging option prints the compiler’s target machine. Simply type:

gcc -dumpmachine

and you’ll get something like this:

i686-pc-linux-gnu

Listing PCI devices

Tuesday, May 4th, 2004

To list PCI devices in GNU/Linux simply type:

/sbin/lspci

or for more info type…

/sbin/lspci -v
/sbin/lspci –help

updating ~/.bashrc and /etc/profile files

Monday, April 26th, 2004

If you have made changes to ~/.bashrc or to /etc/profile, they will only be affective if you login again. You can use the following to avoid this:

source ~/.bashrc

or…

source /etc/profile

Which kernel to load

Monday, April 26th, 2004

I have 3 kernels compiled on my machine and I can select which one to load in memory interactively. When you are in the grub menu select linux..option and then press edit. You will get option like this:

kernel /kernel-2.4.18-14 ro root=/dev/hda5

Now use the TAB key and select among the available kernels you have and press boot.