Archive

Archive for the ‘linux’ Category

Shinken thruk_server.pl compilation error fix

October 26, 2011 Leave a comment

Heard about Shinken when searching for issues related with Nagios and decided to give it a try on my Ubuntu 10.10 (32bit) a try by following this script. Everything went well except then I try to start thruk (the http admin ui) I got the following error

ERROR: this is the wrong precompiled version, your archname is: i686-linux-gnu-thread-multi

BEGIN failed–compilation aborted at /opt/thruk/script/thruk_server.pl line 18.

By looking into the code, the perl script is expecting
/opt/thruk/local-lib/lib/perl5/i686-linux-gnu-thread-multi
but instead I got
/opt/thruk/local-lib/lib/perl5/i486-linux-gnu-thread-multi

So the fix can’t be simpler, simply do

cd /opt/thruk/local-lib/lib/perl5
ln -s i486-linux-gnu-thread-multi i686-linux-gnu-thread-multi
Categories: linux, Shinken

Something to watch out while using ‘%’ in crontab

August 12, 2011 1 comment

% is a special character in crontab and it has to be escaped with another ‘%’ a ‘\’. I just found out through a fail-to-run crontab task:

Non-working version:

1 5 * * *       /bin/bash /path/to/myscript.sh `date +%Y%m%d -d '5 days ago'`

When a crontab fails it will drop an email to user’s mailbox. So here are the relavant lines I found in the mailbox (via command mail):

/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file

With those error messages I googled a bit and changed the crontab to the following
working version:
1 5 * * * /bin/bash /path/to/myscript.sh `date +%%Y%%m%%d -d ‘5 days ago’`

1 5 * * *       /bin/bash /path/to/myscript.sh `date +\%Y\%m\%d -d '5 days ago'`
Categories: linux, Tip

Speed up file copying between hosts

June 7, 2011 Leave a comment

Here’s my test result with transferring a 1.8GB text file to a remote server:

1) scp data user@remote_server:/path/to
2 minutes 48 seconds

2) scp -C data user@remote_server:/path/to
2 minutes 14 seconds

3) rsync -z data user@remote_server:/path/to
1 minute 46 seconds

Method 1) doesn’t use compression at all.
Method 2) enables compression through scp’s -C option.
Method 3) uses rsync with -z (compression) and clearly this method provides the best performance.

Categories: file copy, linux, rsync

Comparing huge text files with rdiff

June 7, 2011 Leave a comment

I happened to need to compare two huge data files (plain texts), each of which is near 2GBs in size. When I use the good old diff program on a Centos with 2GB of Ram and 512MB of SWAP, pretty quickly I got stuck with this error: diff: memory exhausted.

A little googling pointed me to the following solution

http://beerpla.net/2008/05/12/a-better-diff-or-what-to-do-when-gnu-diff-runs-out-of-memory-diff-memory-exhausted/

Categories: howto, linux, rdiff, Tip

Chopping lines with sed in Linux

June 3, 2011 Leave a comment

1) Chop first 1 line from a file
sed -i '1d' filename
[ if need to chop more, simply change 1 to the number of lines to be removed ]
2) Chop last line from a file
sed -i '$d' filename

3) Chop first and last line together from a file
sed -i -e '1d' -e '$d' filename

Categories: linux, Tip

Turning on/off display via Linux command line

May 30, 2011 1 comment

Found the commands at http://systembash.com/content/how-to-turn-off-your-monitor-via-command-line-in-ubuntu/:

To turn off monitor:
xset dpms force off
To turn on, simply press a key, or move mouse/mousepad.

Categories: linux, Tip

Diff text file remotely with local file

May 16, 2011 Leave a comment

Found a pretty neat solution at http://www.genlinux.org/2009/04/remote-diff-in-linux.html for comparing remote and local files. For example, if I want to compare the file

remote_ip:~/myscript.sh with the local version, I no longer have to copy the remote file to a temporary location and do a local diff, instead, with the solution provided in the link above, I can simply do


ssh user@remote_ip 'cat ~/myscript.sh' | diff - path/to/local/myscript.sh
Categories: Bash, linux, Tip