Archive for 2005

Disable IP forwarding

Sunday, December 11th, 2005

If you want to disable IP routing or packet forwarding in Solaris, simply create this file…

touch /etc/notrouter

Protect the file by issuing the next command:

chmod 400 /etc/notrouter

Insufficient memory to execute commands

Sunday, November 27th, 2005

If you have played with Linux computers for a while, it is possible that in some ocassions one of them run out of memory for some reason. In this situation it is impossible to run simple commands such as ls. Recently I’ve read a little trick from Prentice Bisbal at Linux Journal that may help.

From Prentice…

About five years ago, a Linux system I was responsible for ran out of memory. Even simple commands, such as ls, failed with an insufficient memory error. The obvious solution to this problem was simply to reboot. One of the other system administrators wanted to look at a file that may have held clues to the problem, but he couldn’t remember the exact name of the file. We could switch to different directories, because the cd command is part of bash, but we couldn’t get a list of the files, because even ls would fail. To get around this problem, the other system administrator created a simple loop to show us the files in the directory:

$ for file in *; do echo $file; done

This worked when ls wouldn’t, because echo is a part of the bash shell, so it already
is loaded into memory. It’s an interesting solution to an unusual problem.

Cool! Isn’t it? Thanks to Prentice Bisbal.

Portage and nice

Thursday, November 24th, 2005

While you are compiling packages and at the same time you are working with your box, probably you’ll notice the machine is less responsive than usual. Although this in principle is not necessarly an abnormal behaviour it could be very annoying.

To diminish the impact of such situation, you could reduce the priority that the kernel assigns to emerge.

Portage provides a configuration parameter that allows you to control this priority. Edit /etc/make.conf and add the following:

PORTAGE_NICENESS=”17″

This will pass “17″ as value to the nice command. Possible values range from “-20″ to “20″, being “-20″ the highest priority and “20″ the lowest. 0 is standard or normal priority.

See nice man page for more info.

How to delete a file whose name begins with a “-” character?

Saturday, October 8th, 2005

The easiest way to do the job is something as follows:

rm ./-file_to_delete

Another approach that is useful for commands that use getopt to parse the arguments is shown next:

rm — -file_to_delete

This tells the command rm (or whatever command that uses getopt) that anything after “–” is not an option.

Multivolume devices

Tuesday, September 20th, 2005

If you have a big file to back-up to a remote server to which there is a multivolume tape attached, you can tar it even if your device do not change automaticaly the tape:

tar clPM –new-volume-script /root/change_tape \
–tape-length=12582912 –preserve –atime-preserve \
–rsh-command=/usr/bin/ssh -f root@backup:/dev/rmt/2n mnt/backup1

Where…

  • -c is for create
  • -l is for local
  • -P is for preserving the absolute name (or tar automaticaly strip the leading / converting all paths into relative path names)
  • -M is for multivolume
  • –preserve preserves the order and the permitions
  • –atime-preserve preserves the access times
  • –rsh-command=/usr/bin/ssh to avoid using rsh
  • -f for the file to which the back-up goes in. Here we give the user (root) at the server (backup) and the path to the device (the user must have in this machine the right to write to the device and in order to avoid futher complexity to log in the machine without giving a password)
  • –tape-length=12582912 is the length of the tape in kbytes (here is a 12G tape. For testing purposes you can give this option very short numbers to try out the script)
  • –new-volume-script you can give a relative or an absolut path, you can separate with a space or a “=” as you wish

You can use the next script for this purpose (with no guaranty at all, of course). You have to notice that this script is made for a 6 tapes multivolume device. When the 6th tape is full, you have to place new tapes in the device; no script usefull for this ;)

#!/bin/bash
export tape=`ssh root@backup “mtx -f /dev/rmt/2 status”| awk ‘/Empty/ {a= a + 1; if (a == 1) print $3}’| cut -c1`
case $tape in
6)
echo “change the tapes and tip o”
read a
ssh root@backup “mtx -f /dev/rmt/2 load 1″
echo “load 1″
ssh root@backup “mt -f /dev/rmt/2 rewind”
echo “rewind 1″
export tape=` ssh root@backup “mtx -f /dev/rmt/2 status”| awk ‘/Empty/{ a= a +1; if (a == 1) print $3}’| cut -c1`
case $tape in
1)
exit 0;;
*)
exit 1;;
esac
;;

1 | 2 | 3 | 4 | 5)
ssh root@backup “mtx -f /dev/rmt/2 unload”
echo “mtx -f /dev/rmt/2 unload”
ssh root@backup “mtx -f /dev/rmt/2 load `expr $tape + 1`”
echo “load” `expr $tape + 1`
ssh root@backup “mt -f /dev/rmt/2 rewind”
echo “rewind ” `expr $tape + 1`
export tape1=` ssh root@backup “mtx -f /dev/rmt/2 status”| awk ‘/Empty/{ a= a +1; if (a == 1) print $3}’| cut -c1`
echo “tape1 = $tape1″
echo expr $tape1 – $tape – 1
exit `expr $tape1 – $tape – 1`
;;

*)
echo “no tape! Please feed me!”;
exit 1
;;
esac

Determine what program dumped core

Wednesday, September 14th, 2005

When a process causes a memory violation or issues an illegal instruction or something like that it will probably terminate abnormally and will generate a file named core. This file is a memory image of the process.

The GNU debugger, gdb allows you to determine the program that caused the core dump:

gdb -core core.16124

…and you’ll get something like this:

Using host libthread_db library “/lib/tls/libthread_db.so.1″.
(no debugging symbols found)
Core was generated by `kded’.
Program terminated with signal 6, Aborted.

Reverse cat

Wednesday, September 14th, 2005

How to concatenate and/or print files in reverse order? tac is your friend.

From the man page:

Write each FILE to standard output, last line first. With no FILE, or when FILE is -, read standard input.

The easiest way to use it…

tac filename.txt

SchilliX

Tuesday, August 30th, 2005

SchilliX is the first distribution based on OpenSolaris. It is a liveCD and can also be installed on a hard disk on the x86, AMD64 and EM64T based architectures.

According to SchilliX’s website these are the highlights:

  • In 30sec fron bootmanager to multiuser login prompt (HD-boot)
  • Booting from CD or USB-Stick
  • Installs to your harddisk
  • Self healing Services

A quick tour to Solaris 10

Tuesday, August 30th, 2005

Probably at this point you’ve heard a lot of hype regarding Solaris 10. Well, Ben Rockwood’s blog has a quick primer on Sun Solaris 10. Enjoy this nice introduction.

Show shared library dependecies

Monday, August 22nd, 2005

The ldd command lists the dynamic libraries used by a program. This utility is very useful to find out what shared libraries your executables depend on or to do some basic forensic analysis or to help you building chrooted jails.

Simply type this…

ldd /usr/bin/passwd

and you’ll get something like this…

linux-gate.so.1 => (0xffffe000)
libcrypt.so.1 => /lib/libcrypt.so.1 (0xb7fb5000)
libpam.so.0 => /lib/libpam.so.0 (0xb7fab000)
libpam_misc.so.0 => /lib/libpam_misc.so.0 (0xb7fa8000)
libcrack.so.2 => /lib/libcrack.so.2 (0xb7f9c000)
libc.so.6 => /lib/libc.so.6 (0xb7e87000)
libdl.so.2 => /lib/libdl.so.2 (0xb7e83000)
/lib/ld-linux.so.2 (0xb7feb000)