Kung FuKung Fu

Fujian White Crane Kung Fu

ZopeZope

What I have and am doing with Zope

PhotosPhotos

Photoalbum, both old and new.

ReceptsamlingenReceptsamlingen

In Swedish only. About my "Collection of Recipes" website.

Contact meContact me

My contact details and how to contact me.

  Mobile version of this page Mobile version of this page

RSS

Hot topics

by Pete: If you are using bash, you can use echo $PWD/todo.sh...

pwdf - a mix of ls and pwd

by Noah Gift: I agree with you. cron sucks. There was talk on the supervisord list of m...

One thing I hate about Linux: cron

by : And it carry's over to my rdesktopped Windows window. So much value for so ...

Disable Caps Lock in Linux

by : So cool! So nice to get rid of the blasted caps lock (especially for someon...

Disable Caps Lock in Linux

by Peter Bengtsson: Watch this video: http://plone.tv/media/689203036/view fast forward to abou...

How to uninstall nginx with apt

by Peter Bengtsson: I didn't give it a fair test. I just wanted to see if I could get Zope to r...

How to uninstall nginx with apt

by Parand: What was your general impression of nginx and what made you decide to remov...

How to uninstall nginx with apt

by martin: THANKS!!!! Exactly what im looking for. Greetz from germany, Martin...

Read in passwords with bash

by ivo: rm -f foobar.html will not complain if the file doesn't exist...

File check before delete

by betabug: Try `whois 80.68.212.7` for a change... requires more reading skills, but g...

hostip.info - Look up the location from an IP

Old entries


February, 2008
hostip.info - Look up the location from an IP
CommandLineApp by Doug Hellmann
If Americans knew - An interesting insight into the Israeli Palestine conflict
Chinese New Year and the Persecution of Falun Gong in China
logrotating all my Zope event logs
Ocado gets customer service right
Why Django and Grok matters

January, 2008
The Official Dilbert Widget
"lost my phone :("
Ugliest e-commerce site of the month - Comfy-Feet
input/textarea switcher with jQuery
jQuery and Highslide JS
The Love Mattress
EditArea vs. CodePress

2007
2006
2005
2004
2003

 

You're viewing blogs from Linux only.

View all different categories

7th of April

pwdf - a mix of ls and pwd

I often need to know the path to a file so that I can put that in an email for example. The only way I know is to copy and paste the output of pwd followed by a slash / followed by the name of the file. This is too much work so I wrote a quick bash script to combine this into one. Now I can do this:

 $ cd bin
 $ pwdf todo.sh 
 /home/peterbe/bin/todo.sh

I call it pwdf since it's pwd + file. Here's the code for the curious:

 #!/bin/bash
 echo -n `pwd`
 echo -n '/'
 echo $1

Is there no easier way built in into Linux already?

31st of March

One thing I hate about Linux: cron

First of all, I understand that the problem cron solves is a hard one but come on, it's been many years now without much progress. At least not in the usability field of cron jobs. Secondly, I don't know of an operating system that does this better. Perhaps there is one. All I'm saying here is that this aspect of Linux sucks. The issues I have with cron are:

Beef number 1 Is it root, user1 or user2 running a crontab job? I'll have to su into each suspected user and run crontab -l. Granted, some jobs require root access and others don't but it nevertheless makes it hard to find the configured jobs when maintaining someones server.

Beef number 2 Even though they do such a similar thing, it feels like /etc/cron.* is a different battlefield from crontab. Why can't this all be in one coherent place?

Beef number 3 The crontab syntax. How difficult would it be to allow an interface to accept user input as "every 10 minutes" or "01.30 every day"?

Beef number 4 With there being 12 different ways (sarcasm) to write cron job scripts there's no coherent place to collect all log and errors that happen from cron. Couldn't it be default to always write to /var/log/cron/access.log and all executions that cause a write to stderr could append to /var/log/cron/error.log

I don't think Anacron would make me any happier since the problem Anacron solves was not one of the problems I listed above. And lastly, I wouldn't be surprised if there's a semi-abandoned Open Source project on SourceForge that is user friendly but what I'm after is something to get into stock Linux. Kind of like apt/aptitude/dselect is for dpkg maybe?

28th of March

How to uninstall nginx with apt

My colleague Jan showed me how to do this so I'm going to blog about it to not forget and perhaps by being here other people might be able to search and find the solution too. I installed nginx because I wanted to play with it as an alternative to apache on my laptop. Now I've played enough and I'm going to want to remove it. My first attempt didn't work:

 peterbe@trillian:~ $ sudo apt-get --purge remove nginx
 Reading package lists... Done
 Building dependency tree
 Reading state information... Done
 The following packages will be REMOVED:
  nginx*
 0 upgraded, 0 newly installed, 1 to remove and 116 not upgraded.
 1 not fully installed or removed.
 Need to get 0B of archives.
 After unpacking 528kB disk space will be freed.
 Do you want to continue [Y/n]?
 (Reading database ... 242827 files and directories currently installed.)
 Removing nginx ...
 Stopping nginx: invoke-rc.d: initscript nginx, action "stop" failed.
 dpkg: error processing nginx (--purge):
  subprocess pre-removal script returned error exit status 1
 Starting nginx: invoke-rc.d: initscript nginx, action "start" failed.
 dpkg: error while cleaning up:
  subprocess post-installation script returned error exit status 1
 Errors were encountered while processing:
  nginx
 E: Sub-process /usr/bin/dpkg returned an error code (1)

I tried this both before and after having stopped and started nginx. Nothing worked. The trick is to fiddle with the init script /etc/init.d/nginx and insert a exit 0 at the top so that it now starts like this:

 #!/bin/sh
 exit 0

Once saved and you try apt-get --purge remove nginx it will work. It might warn you that /var/log/nginx aren't removed because they're not empty but you can safely remove them manually unless you want to keep them.

6th of March

File check before delete

Because I always forget, here's how to check if a file exists before attempting to delete it in bash:

 [ -f foobar.html ] && rm foobar.html

If you don't do it this way and the file doesn't exist you get this:

 rm: cannot remove `foobar.html': No such file or directory

29th of February

hostip.info - Look up the location from an IP

http://www.hostip.info/ 

I've never really needed it but I've been looking for a tool that is super easy to use that quickly looks up the location of an IP address. The super easy tool is called hostip.info and this is what happens when you do a lookup on www.peterbe.com's IP at http://api.hostip.info/get_html.php?ip=80.68.212.7 :

 Country: UNITED KINGDOM (UK)
 City: (Unknown city)

Cool. I'll remember that till next I really need this. I discovered hostip.info by reading this cool blog by Corey Goldberg

6th of February

logrotating all my Zope event logs

I've installed a lot of Zope instances on my laptop since version 2.7.3 and out of curiosity and desperate need for more hard drive space I thought I'd log rotate them all with the standard Linux logrotate program.

Before doing the log rotate, the total size of all my event.log files came to about 290Mb! After running logrotate (twice of course to go from event.log.1 to event.log.2.gz) the total size become 20Mb. Not a huge significance in the world of gigabyte hard drives but at least something.

27th of September

Linux tip: du --max-depth=1

There are lots of fancy programs for Linux to find out where your gigabytes are sitting and filling your hard drive, the simplest of them is du (from disk usage). The trick is to use the --max-depth=1 option so that you get a view of which folder weighs how much. Try this:

 peterbe@trillian:~/tmp $ du -h --max-depth=1
 900K    ./Example-Receipts
 4.0K    ./Foredettinghelgen
 44K     ./IssueTrackerBlogInterface
 1.9M    ./IssueTrackerProduct
 12K     ./fried-mugshots
 2.1M    ./ies4linux-2.0.5
 4.8M    ./pyexcelerator
 52K     ./levenstein
 4.0K    ./newitpdesign
 4.7M    ./photoresizing
 69M     ./databases
 4.5M    ./i18nextract-sa
 532M    .

Pretty nifty! That way you can quickly see which folder contains the most junk so that you can free up some hard drive space.

To sort it I don't know how to reformat it into human readable values but there's the command:

 peterbe@trillian:~/tmp $ du --max-depth=1 | sort -n
 4       ./Foredettinghelgen
 4       ./newitpdesign
 12      ./fried-mugshots
 44      ./IssueTrackerBlogInterface
 52      ./levenstein
 900     ./Example-Receipts
 1856    ./IssueTrackerProduct
 2140    ./ies4linux-2.0.5
 4528    ./i18nextract-sa
 4796    ./photoresizing
 4872    ./pyexcelerator
 70392   ./databases
 544608  .

24th of August

Printer usability problem

Printer usability problem I booked an appointment for a computer repair today and there was a reference number and summary that I was told to print two copies of. One to go with the computer and one to keep myself as a reference. The page was one page long. So, in Firefox I clicked to print two copies. Our printer here at work is one of those that prints on both pages and that's where the problem lies. It printed the two copies one of each side. So only one piece of physical paper. Totally stupid.

I don't know what or who to blame for this. Is it my Firefox? My Dell printer? My Linux printer drivers? Surely there was a chance for someone working on this some time ago who chose not to think for a moment.

7th of June

FacebookStatusUpdater

FacebookStatusUpdater This is silly but fun. I can with one command on the command line start updating my Facebook profile. It's not using the Facebook Developer API but a PHP script I copied from some other blog I can't find right now. Here's how I use it:

 peterbe@trillian:~ $ FacebookStatusUpdater 
 Peter is happily blogged about his latest facebook status updater
 Updating Facebook...

It's an interactive prompt and starts with "Peter is " and then I write till I hit the Return and it gets uploaded and saved. See attached screenshot.


>Read the whole text (69 more words)

7th of February

Comparing REAL values in PostgreSQL

Long story short, if you need to compare floating point numbers against columns defined as REAL you need to first cast them to NUMERIC in PostgreSQL. And to compare equality between two numbers with different amount of significant figures you have to use ROUND().


>Read the whole text (166 more words)

10th of January

Flash 9 on Ubuntu Edgy Eft

My Ubuntu Linux on my work laptop works great but since I've strayed far away from the default options (own kernel, own window manager etc) some things sometimes don't work as expected. Such as Flash9. The problem I had was that there some some package in there that was broken for some reason: libswfdecmozilla.so

Here's what I did:

 # cd /usr/lib/mozilla/plugins
 # rm libswfdecmozilla.so
 # wget http://download.macromedia.com/pub/labs/flashplayer9_\
 update/FP9_plugin_beta_101806.tar.gz
 # aunpack FP9_plugin_beta_101806.tar.gz
 # mv flash-player-plugin-9.0.21.55/libflashplayer.so .
 # chmod +x libflashplayer.so

Start firefox and enter about:plugins and this is what you should see

That worked for me. Hopefully this will help somebody. The help I got from this page which might also help people with a broken Java in Firefox but they don't say that you should delete the libswfdecmozilla.so driver.

UPDATE

There's a slightly more recent beta now. The November 2006 beta

UPDATE 2

Now there's a final release on adobe.com

29th of December

Find largest directories with du -k

Here's a nifty little command I used today to find where my hard drive was being most used:

 du -k /home/peterbe/Documents/ | sort -n | tail -10

I'm sure there are even fancier methods and programs but this works pretty damn well. Here's what the output can look like:

 root@trillian:~ # du -k /home/peterbe/Documents/ | sort -n | tail -10
 4240    /home/peterbe/Documents/Kalle
 4852    /home/peterbe/Documents/ChartDirector/lib
 7756    /home/peterbe/Documents/ChartDirector/doc/cdpydoc
 7764    /home/peterbe/Documents/ChartDirector/doc
 13044   /home/peterbe/Documents/*** FONT _ ***/- Font Applications -
 14704   /home/peterbe/Documents/ChartDirector
 547940  /home/peterbe/Documents/*** FONT _ ***
 2171000 /home/peterbe/Documents/MacOSXSoftware/Adobe Creative Suite 2 Premium
 3262580 /home/peterbe/Documents/MacOSXSoftware
 5694808 /home/peterbe/Documents/

9th of December

ImageMagick conversion comparison

I have an application where I need to resize huge digital camera pictures down to 800x600 pixels. To do this I used ImageMagick's convert program which I feel gives much better quality than Python PIL. To reduce the file size I make sure I use the -strip option to convert but the really interesting question was what quality option should I use?

Goal: the image should be as small (in bytes) as possible without too reduced in picture quality.

To get the optimal picture quality of course the right option is -quality 100 and to get the smallest file size I should use -quality 10. To find out what quality setting to use I converted an original image with the following command 10 times:

 convert vase.jpg -strip -quality <X> -resize 800x600 vase.quality-95.jpg

where <X> is the varying value between 10 to 100.


>Read the whole text (90 more words)

1st of November

Memory dump blog recovery

My Firefox froze in one of the tabs when in another tab I had a long Fry-IT intranet blog half finished. To avoid having to rewrite the whole text again Jan showed me how to dump the RAM memory onto disk which I could then look through with standard tools. For this to work you have plenty of diskspace since the dump file is about 1Gb big:

 $ sudo su -
 # df -h
 # cat /proc/kcore > /usr/kcore.dump
 # strings /usr/kcore.dump > /usr/kcore.strings
 # ls -lh | grep kcore
 -rw-r--r--   1 root    root    1016M 2006-10-30 10:18 kcore.dump
 -rw-r--r--   1 root    root      74M 2006-10-30 10:19 kcore.strings
 # less kcore.strings | grep 'Bla bla bla'

Was this the most boring blog item I've written in a long time? Maybe, but it's good to have it noted the next time Firefox crashes.

23rd of October

Catching a carriage return in bash

I'm not a bash expert. Now I need some help with some bash syntax.

I copied a function called get_key which takes a 1 character length string from the stty input and assigns it to a variable. It's nifty because I can prompt something like this:

 Select task:
 1 - Task XYZ
 2 - Task F19
 3 - Task 123
 q - quit


>Read the whole text (465 more words)

 

Older entriesOrder entries