unix

Blank page detection on the command line with imagemagick

Tagged:  

So you've got some scanned pages or images in some format like PDF or jpg and you want to find all the blank ones.

You can use imagemagick to do this. This solution should be able to handle variations in page color, page noise, etc.

Here is how to do it in the shell.

Disk overwrite speed: cat vs dd vs shred

Tagged:  

Ever wonder which can fill a disk with random bits the fastest?

command time in seconds to overwrite 1000M
cat /dev/urandom > /dev/hda1 238.56
dd bs=16k if=/dev/urandom of=/dev/hda1 240.36
shred -n 1 /dev/hda1 240.92

As you can see, cat is fastest, though not by much -- on a big disk it might save you a couple of minutes.

I tried several blocksizes with dd, from 1k to 50M, and bs=16k came out to be the fastest.

Automatically add and remove groups to a user

Tagged:  

So I wanted to write a shell script to add groups to users. I found out that usermod can only set all group memberships at once, there is no way to simply add one group at a time.

I wrote a perl script to do what I want. Just call it with -a 'group' to add a group to a user and -d 'group' to remove a group. You can comma seperate multiple groups or use multiple switches on the command line. Of course you have to be root.

Note that this script makes assumptions about the output of the groups command. It expects groups to output like "user : initialgroup extended1 extended2"

Maybe I will clean it up one day to not use the groups command and do more sanity checks. Right now it relies on usermod to check that users and groups exist.

Syndicate content