batch resize photo on Linux

linux, tools | Thursday June 3 2010 8:00 pm | Comments (0)

if you are like me and you have a photo gallery to share your photo to your friends and family and other people, you may have come across the problem of resizing your photos. With a camera taking 4MB photos, I don’t want people to wait 1mn between each photo they look at so I resize them. You could say that I could use picassa or anything else like that but those services and other look-a-like don’t completely suit me.

Anyway, if you want to do that in a couple of secondes  on your favourite Linux distro, you need ImageMagick. It’s a very good command line tool that will allow you to script (or just manipulate)  your photo. Very useful  when you come back from a Safari with 2000 photos :)

you can usually find ImageMagick packaged for every distro but I’ll show you here how to get it for Debian (or any other distro using apt-get …)

sudo apt-get install imagemagick
cd ~/photos/myphotos/
mkdir resized
cp *.jpg resized
cd resized

ImageMagick doesn’t create a new photo smaller but actually resize it so that’s why you should keep a copy of your photos if you want to keep them in the original size.
The command to use is mogrify. It’s always good to have a look at the man page but you basically just need to do as follow to resize a photo -

To resize all the photo with a max height or weight:

mogrify -resize 1920 *.jpg

Or to give a fix size:

mogrify -resize 1024×786! *.jpg

You can do much more with ImageMagick so have a look by yourself!!!

Red Hat: where is the crisis ??

linux | Wednesday July 1 2009 6:44 pm | Comments (0)

Red Hat has published it’s results from the first quarter and the only thing we can say is that RH is doing well! results up 11% from the year ago quarter. The net income for the quarter is 18.5 millions, a 7.1% growth.
This is realy good and show that the open sources technologies get more and more interest from companies, especially on recession !
An other interesting figure is that now 61% of the sales are made by the business partner network. It show that the can rely on more that just themself and they need it to keep growing.

An interesting annonce was that they annonced the beta release of a portfolio of products around virtualisation (Red Hat hypervisor is KVM).

Linux is running too fast…

VMware, linux | Monday June 15 2009 11:50 am | Comments (3)

If you still use VMware GSX and/or VMware server 1, and some of your guest are Linux, you may have already encountered this issue. This might seems not useful as those VMware products are quite old now, but when it’s on production, you don’t really get rid of something easily :D

The clock of the system is always de-sync even with a ntp server configured on it. This is a big issue when you run automated script with cron, and you’re system backup is done at 10am instead of 5am… That’s because your CPU clock is running too fast or too slowly. This is a known issue on those product as they don’t support host power management features on Linux properly.

To sort this out, you just to do the following:

you first need to know your CPU speed

~cat /proc/cpuinfo | grep MHz

cpu MHz         : 3601.737

edit the file /etc/vmware/config and add

host.cpukHz = 3601737
host.noTSC = TRUE
ptsc.noTSC = TRUE

host.cpukHz change depending the output of the fisrt command. It’s basically the CPU speed in Hz.

if not already done, you need to install the VMware tools on the guest and configure the time synchronisation. You can do it either by editing a file or in the options of the VM tools in a graphical interface.
The file to edit is the .vmx file and the line to add is tools.syncTime = “TRUE”

Once it’s all done, you’ll have to reboot the guest and restart VMware on the host.

If the problem is not fixed, this may be addressed by disabling power management altogether. This can be done by adding “apm=off acpi=off noapic” to the boot entry of the host’s /etc/grub.conf file.

Capacity Management for QNAP NAS

Script, linux | Friday June 12 2009 6:15 pm | Comments (0)

I’ve got 2 TS-409 NAS appliance from QNAP. They are configured in raid5 and data are synchronised between them. As there is no possibilities to monitor the disk usage (no SNMP or any other things like that), I decided to create a little script which send an email when the disk usage reach 90%

This is not a big deal as it only contain few lines and is really straightforward, but I actually spent 2 hours to figure out how I could send this bloody email… Again, nothing difficult, just that I started in the wrong direction. i wanted to send it through a telnet connection on port 25 of the mail server… The only problem is that it was fine on any linux with a proper telnet binary, but the telnet implementation on busybox is different and doesn’t work when I try to telnet the smtp port of our exchange… So I just used ssmtp, already included and it works like a charm.

The script could obviously report a lot more but that’s what I’ve been asked :D

#!/bin/sh

FROM="FROM: Nas1@xxx.yyy"
TO="someone@xxx.yyy"
RCPT="TO: $TO"
SUB="Subject: Test Alert"
BODY="The NAS is filled at XXX%"

dfresult=`df -h /dev/md0 | grep /dev`
position=`expr index "$dfresult" %`
let position=$position-3

if [ ! ${dfresult:$position:1} == "" ];then
   value=${dfresult:$position:2}
   if [ $value -ge 90 ];then
      BODY=${BODY/XXX/$value}
      (echo "$RCPT";echo "$FROM";echo "$SUB";echo "";echo "$BODY") | ssmtp $TO
   else
      echo "not critical"
   fi
else
   echo "less than 10%"
fi

exit 0

It wouldn’t be difficult to add few more things like add how many GB left, and things like that but I’ll let you do it :D

Kernel Korner: 2.6.30 out

linux | Wednesday June 10 2009 4:16 pm | Comments (0)

Here we are! The new kernel has been released today after 8 release candidate and bring some interesting new features along driver update and bugfix. I won’t go into details but here are the main thinks:

  • - Improvement on Ext3/4
  • - The file system NILFS (New Implementation of a Log-structured File System) has entered in the mainline. Developped by the Japanese company NTT, this FS improve writs on the detriment of reads. the general performances seems even better than BTRFS though
  • - Exofs (Extended Object File System) is an other “new” FS for SCSI disks, who is based on object and metadata instead of low level blocks an sectors and is developed by SUN
  • - POHMELFS (Parallel Optimized Host Message Exchange Layered File System) is again a new FS, but it’s purpose is having a high performances network file system (like NFS, CIFS, …) but with paralleled access to nodes.
  • - FS-Cache has finally been ported on the kernel and allow to improve network file systems performances by caching the data.
  • - TOMOYO is the new security module created to be much easier to manage than SELinux.
  • - IBM has pushed a set of patch to port Integrity management in the kernel. This provide some sort of assurance that the files on the system have not been messed with.
  • - The mutex code has been amended to introduce a new mechanism in it. the patch changes mutex contention behaviour such that it will sometimes busy wait on acquisition to move its behaviour closer to that of spinlocks.
  • - Reliable Datagram Sockets (RDS) protocol is now supported and improve clusters performances by bringing improvement on process when the talks to other processes on the cluster.
  • - The asynchronous function call infrastructure is now activated. It allows to query storage devices asynchronously on kernel boot, which makes it quicker.
  • - The new MicroBlaze architecture is now suported
  • - The integrity controle on block devices introduced on 2.6.27 has been extended to raid configurations.
  • - The kernel can be compressed with bzip2 and lzma algorithms to gain between 10% and 33% of the gziped sizw
  • - Improvements on dm-crypt for multi-core CPUs
  • - Harware acceleration AES encryption for futur Intel Westmere CPU
  • - Support for AMD/ATI R6xx/R7xx graphic cards
  • - Extend of the 4GB ram limit for ARM architecture
  • - General improvements of ftrace (Linux Dtrace like)
  • - Enhancement of cpufreq
  • - SSP (Secure Simple Pairing) for bluetooth 2.1 is now suported
  • - Enhancement of SSD drives performances through the implementation of the TRIM command
  • - Support of the SEGA Dreamcast console improved
  • - Driver update for ALSA (1.0.20) and V4L

As you can see there is quite a few new thinks about file systems. I might post something about all that as it’s been a quite busy area lately with EXT4, Btrfs, …
The Kernel 2.6.30 represents 11912 patches and one million and half lines of code modified, which makes it a quite big development cycle.

More details about the new drivers
This is just a quick look at what’s new on the Kernel, you can get much more informations there

PuTTy Connection Manager

linux, tools | Wednesday June 10 2009 12:03 pm | Comments (1)

I recently found a tool that help me a lot on my duties at work! It’s called PuTTy Connection Manager. No it’s not just the putty that everyone knows. It’s an application that actually come on top of putty to enhance it. As you can see below, the main feature is tabs. But don’t tell me, if you are an unfortunate user of putty like me (not that putty is not good but I’d prefer to use a Linux OS at work. Therefore, I wouldn’t have to use putty…), that you never thought that putty would be much better with tabs!!!

PuTTy Connection manager

PuTTy Connection manager

PuTTy Connection Manager require the .NET framwork V2 and Encryption library 0.6.0.0 if you want to encrypt your database.

Unfortunately, the project (French :D) seems to be dead and it’s not open sources… But it got to a point where I don’t really need much more features and there is no important bug. If you know any PuTTy-like tools better than this one, and preferably still alive, let me know, it might be interesting :D

You can download the latest version here
And the website is here

Quick reminder to enable kernel dump on rhel4

linux | Tuesday June 9 2009 4:15 pm | Comments (5)

Nothing new here but I’ll use this post as a quick reminder to enable kernel dump on red hat enterprise 4. Quite useful when you don’t know why your box keep crashing this week when it was perfectly fine for the last 2 years :D

Red Hat historically use netdump in order to save a kernel dump file but since RHEL 4, they introduced diskdump. Which is good as I don’t want to bother set-up a netdump server (even if there is few interesting thinks in favour of netdump, like “what if your system doesn’t recover…”). You can easily understand the main difference between them… The first one create the file over the network using a server (like if you have a syslog server) while the other one use a local disk.
Here the few steps to follow:

Everything should be already installed, but in case it’s not on your system:

# up2date crash diskdumputils

crash is an utility used to analyse the dump file.

Check the loaded kernel modules, if not already loaded, then do it.

# lsmod | grep diskdump
# modprob diskdump

Configure what partition you want to use. 2 choices: 1st you have a partition only for this purpose, 2nd you can use a swap partition. if you don’t use a swap partition, you’ll have to format it. The size of the partition you choose must be at least the size of your ram.

# cat /proc/swaps
# vi /etc/sysconfig/diskdump

You can specify more than one partition if you separate them by ‘:’

DEVICE=/dev/sda4:/dev/sda5

If you didn’t choose a swap partition, then you have to format your device in order use it as a dump device.

# service diskdump initialformat

Tell your system to start diskdump automatically at the next reboot and start it.

# chkconfig diskdump on
# service diskdump start

If you get a warning, it may just means that your partition is not good (wrong partition specified in /etc/sysconfig/diskdump, or forgot to format, …)

check that the module works fine. the output must be something like the following:

# cat /proc/diskdump

# sample_rate: 8
# block_order: 2
# fallback_on_err: 1
# allow_risky_dumps: 1
# dump_level: 0
# compress: 0
# total_blocks: 2097059
#
sda4 4401810 4192965
sda5 8594838 4192902

When a crash occures, the data from the disk dump partition are not directly readable. You need to gather them in a file on a readable partition. This is done with the following command:

# savecore -vD /dev/sda4

You can add this command to /etc/rc.local if you want to run it automatically after a crash.

This is it! Next time your kernel crashes, you’ll get a file called vmcore stored in /var/crash/127.0.0.1-\/. If for any reason the dump is not complete, the file will then be named vmcore-incomplete

You can test if it works fine by doing one of the following things. It will result on you server crashing therfore creating a dumpfile.

# Alt-SysRq-C or
# echo c > /proc/sysrq-trigger or
# echo 1 > /proc/sys/kernel/sysrq

you can also quickly compile the following code [cc -c -I/usr/src/linux/include panic.c]
and load this nice module :D [insmod panic.o]

#### panic.c #####

#define __KERNEL__
# MODULE
# include init_module(void)

int init_module (void)
	{
	panic(" panic has been called");
	return 0;
	}

now in order to analyse your dump, crash require the kernel debuginfo package corresponding to the kernel you are running. You can find it there. Then you need to install it.

wget http://updates.redhat.com/enterprise/4AS/en/os/Debuginfo/i386/RPMS/
kernel-debuginfo-2.6.9-89.EL.i686.rpm && \
     su -c "rpm -Uvh kernel-debuginfo-2.6.9-89.EL.i686.rpm"

After your kernel panic and a reboot, you can now run crash with the following arguments (vmlinux_path vmcore_path).

# crash /usr/lib/debug/lib/modules/2.6.9-89.EL/vmlinux \
        /var/crash/127.0.0.1-2009-06-07-14\:44/vmcore

OUTPUT
      KERNEL: /usr/lib/debug/lib/modules/2.6.9-89.EL/vmlinux
    DUMPFILE: /var/crash/127.0.0.1-2009-06-07-14:44/vmcore
        CPUS: 1
        DATE: Tue Jun  8 15:02:44 2009
      UPTIME: 00:51:24
LOAD AVERAGE: 0.05, 0.05, 0.00
       TASKS: 81
    NODENAME: rhxxx.test.xxx.org.uk
     RELEASE: 2.6.9-89.EL
     VERSION: #1 Fri Feb 24 16:44:51 EST 2006
     MACHINE: i686  (3600 Mhz)
      MEMORY: 1.5 GB
         PID: 3514
     COMMAND: "crash"
        TASK: f562ecd0  [THREAD_INFO: f4b7d000]
         CPU: 0
       STATE: TASK_RUNNING (ACTIVE)

I leave you find out all the things you can do with crash (try a “man crash” or help once you ran crash) but the command ‘log’ and ’sys’ will be the one you are going to use the most.

you can find much more details here
Enjoy :D