Archive for the ‘Ubuntu’ Category

It’s the little things I like about Linux

Tuesday, January 8th, 2008

Today I wrote some handy syncronization-scripts with the help of my freebsd-loving co-worker Marius. Till today I managed the syncronization of my local database with our production database with the help of phpMyAdmin.
An export of the 13mb sql file at the production server and an import at my machine took me at least five minutes (~2mb gzipped). Now take a look at this:

[hans@zommuntu:~]$ time ssh user@production_server "mysqldump --add-drop-table database_to_process -uUSER -pPASSWORD | gzip" | gunzip | mysql -uLOCALUSER -pLOCALPASSWORD database_name
real    0m4.389s
user    0m0.592s
sys     0m0.052s

Under five seconds! woot!!
Some words to explain this: First, you establish a ssh connection to the production_server. The gzipped dumped sql of the beloved database_to_process is transferred to your machine. Here it is gunzipped and written to your local database server into the database_name. The quotes are necessary as brackets to let the script know that the gzip command belongs to the ssh command.

Translate directly at your console!

Monday, January 7th, 2008

Ever wanted to be able to translate directly at your cosole?

[hans@zommuntu:~/rails]$ de2en häuser
Homes
[hans@zommuntu:~/rails]$ en2de houses
Häuser

Save this ruby-script as en2de in your ~/bin:

#! /usr/bin/ruby

#
# Copyright (c) 2008 gauda.de
# All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Ruby itself.
#

require 'net/http'
require 'iconv'
require 'uri'

arg = URI.escape(Iconv.new('ISO-8859-15', 'UTF-8').iconv(ARGV[0]))
str = Net::HTTP.new('www.google.com', 80).get("/translate_t?text=" + arg + "&langpair=de|en").body.match(/id\=result_box\ dir\="ltr">(\S*)<\/div>/)
if str
  puts Iconv.new('UTF-8', 'ISO-8859-15').iconv(str[1])
else
  puts "error.."
end

Of course you can change the languages! Just edit the langpair=de|en at your will. Be sure to have ruby installed!

My changeConfiguration.sh script to change single- and dual-monitor and network configurations

Monday, December 31st, 2007

My old notebook Fujitsu-Siemens Lifebook S7010 drove an Intel graphics card whose driver wasn’t able to detect the plugging of external monitors. So I wrote a little script to switch my xorg.conf file:

#!/bin/sh
if diff /etc/X11/xorg.conf /etc/X11/xorg.conf.single >/dev/null 2>&1
then
sudo cp /etc/X11/xorg.conf.dual /etc/X11/xorg.conf
echo 'monitor: dual'
else
sudo cp /etc/X11/xorg.conf.single /etc/X11/xorg.conf
echo 'monitor: single'
fi

It is also possible to switch between different network configurations. The reason for me was that I was able to use LAN in the office and use WLAN at home. Just append this to your changeConfiguration.sh:

if diff /etc/network/interfaces /etc/network/interfaces.home >/dev/null 2>&1
then
sudo ifdown eth0
sudo ifdown eth1
sudo cp /etc/network/interfaces.office /etc/network/interfaces
sudo ifup eth0
sudo cp /etc/resolv.conf.office /etc/resolv.conf
echo 'network: office'
else
sudo ifdown eth0
sudo ifdown eth1
sudo cp /etc/network/interfaces.home /etc/network/interfaces
sudo ifup eth1
sudo cp /etc/resolv.conf.home /etc/resolv.conf
echo 'network: home'
fi

Now, how does this work? First, create configuration files for each setup in the appropriate folders. In the first example it is /etc/X11/xorg.conf.single and /etc/X11/xorg.conf.dual, in the second example it is /etc/network/interfaces.office, /etc/network/interfaces.home, /etc/resolv.conf.home and /etc/resolv.conf.office. Put your configuration into these files.
This is no catch-it-all-script, you have to switch to another terminal screen (e.g. Ctrl + Alt + F2) and call the script: sh changeConfiguration.sh. It will tell you if you are driving single- or dual-screen and which network configuration you’ll use. Restart your X-server after calling.