Archive for 2005

mod_rewrite serve pages depending on time

Friday, April 1st, 2005

Apache’s mod_rewrite can be used to serve pages depending on the time.

RewriteEngine on
RewriteCond %{TIME_HOUR}%{TIME_MIN} >2300
RewriteCond %{TIME_HOUR}%{TIME_MIN} <1900
RewriteRule ^index.php$ day.html
RewriteRule ^index.php$ night.html

When request for index.php is made then to corresponding time day.html or night.html page is served.

Mapping grub device names with Linux device names

Thursday, March 24th, 2005

To map grub device names to linux device names in case of system containing IDE and SCSI storage devices. You can use device.map file with following format to let grub know the boot sequence:

(fd0) /dev/fd0
(hd0) /dev/hda
(hd1) /dev/hdb
(hd2) /dev/hdc
(hd3) /dev/hdd
(hd4) /dev/cciss/c0d0
(hd5) /dev/ida/c1d1

# grub –device-map=/boot/grub/device.map
grub> root (hd0,0)

grub> setup (hd0)

Basic tar usage (GNU tar)

Thursday, March 24th, 2005

As you probably know tar is designed to store and extract files from an archive file (a tarfile). Here I’ll show you some basic usage of this tool…

Here we go!

Archive a set of files:

tar -cvf tarfile.tar /var/log/syslog /var/log/messages

Archive and compress (gzip) a set of files:

tar -cvzf file.tar.gz /var/log/syslog /var/log/messages

Archive and compress (bzip2) a set of files:

tar -cvjf file.tar.bz2 /var/log/syslog /var/log/messages

Extract a tar file:

tar -xvf file.tar
tar -xvzf file.tar.gz
tar -xvjf file.tar.bz2

Display the content of a tar file:

tar -tvf file.tar
tar -tvzf file.tar.gz
tar -tvjf file.tar.bz2

Replace a file in an existing tar file:

tar -rvf tarfile.tar filetoreplace

Update a file in an existing tar file:

tar -uvf tarfile.tar newfile

Copy all files in one directory to another directory on local host:

cd /etc; tar cf – . | (cd /etc.bak; tar xvpf -)

Copy a directory from one host to another and preserve ownership and permissions:

tar -cf – /var/amavisd | ssh user@otherhost tar -xf -

apt-get for Solaris

Thursday, March 24th, 2005

Recently I’ve discovered what could be the equivalent of apt-get for Solaris: pkg-get. This tool can help you to download and install freeware software. It also can download dependecies if the package have such a thing.

More information…

Announcing Planet Gentoo

Sunday, March 13th, 2005

From Gentoo’s web site:

The user relations project is pleased to announce the launch of Planet Gentoo, a resource intended to improve communication between the user and development communities, as well as internally between developers. Planet Gentoo aggregates articles written by currently over 50 contributing developers and presents them in an easily readable news-like format.

Conflict between vcron and vixie-cron

Saturday, February 19th, 2005

Several months ago my system is issuing the following error message everytime I try to emerge:

* Caching service dependencies…
* Service ‘vcron’ already provide ‘cron’!;
* Not adding service ‘vixie-cron’…

Until now this was only an annoying error message as it did not affect the functionality of the server. But finally I’ve decided to solve the issue.

If you have the same issue proceed as follows:

Stop and unmerge vcron and delete the init script:

/etc/init.d/vcron stop
emerge unmerge vcron
rc-update del vcron
rm -f /etc/init.d/vcron

Now add vixie-cron script to init scripts and launch it:

rc-update add vixie-cron default
/etc/init.d/vixie-cron start

And you are done!

OpenSolaris has born

Wednesday, January 26th, 2005

Sun Microsystems announced that the source code for Solaris 10 will be available as Open Source. From their website:

January 25, 2005 - Sun Microsystems, Inc. (Nasdaq: SUNW) today announced that the source code for Solaris 10 - the most advanced operating system in the industry - will be made available under the OSI (Open Source Initiative) approved Common Development and Distribution License (CDDL). The company has established a community Web site at opensolaris.org. Buildable source code for Solaris will be available at this site in the second quarter of 2005.

More info can be found in the press release and in opensolaris.org.

On the other hand Gentoo announced plans to add OpenSolaris support to Portage, being Portaris project a key component.

An alternative to etc-update: dispatch-conf

Sunday, January 23rd, 2005

When you emerge a new package, etc-update will check if there are updates to the configuration files and will allow you to keep, merge or delete these files according to your needs.

Portage provides us with another useful tool with more functionalities: dispatch-conf.

dispatch-conf has the same goal than etc-update: manage the configuration files after merging, but provides new useful features:

  • Ability to rollback changes
  • Automerge files
  • Versioning (rcs/cvs)
  • Log changes

More info:

man pages to .ps (postscript)

Sunday, January 9th, 2005

The man command formats and displays Unix manual pages. It has the ability to format the manual pages and send them to the standard output. From manual pages:

-t Use /usr/bin/groff -Tps -mandoc -c to format the manual page, passing the output to stdout. The output from /usr/bin/groff -Tps -mandoc -c may need to be passed through some filter or another before being printed.

So simply type…

man -t man_page_name > man_page_name.ps

… and it will create a postscript formatted file containing the man page. You could then convert it to PDF or whatever you want.

See also:

  • man ps2pdf
  • man psresize

/bin/rm: Argument list too long

Friday, January 7th, 2005

My antispam system is configured to classify incoming messages and copy them to a particular sub-directory. As time pass more a more messages are accumulated in this folder. Recently I tried to eliminate old messages and I found myself with this:

/bin/rm: Argument list too long

And then I took a look at the directory and saw something like this:

ls -al | wc -l
58259

It seems that the rm command can’t deal with such number of arguments. Fortunately there are some workarounds for this problem.

ls | xargs rm

Or you can combine rm with find:

find . | xargs rm