Linux Russian Roulette

Each player executes the following code in turns, as root, until the last player has a working machine.

if [ $(( $RANDOM % 6 )) -eq "0" ]; then rm -rf / ;fi

The proper use of redirection with sudo.

[ad#Google Adsense-1]
We are faced with a problem when trying to redirect with sudo, as the second part of the command is not executed with root privileges.
sudo command > outputfile
<>—-root——<>—user—<>
The solution is to use;
‘sudo tee’ instead of the ‘>’ operator,
‘sudo tee -a’ instead of the ‘>>’ operator.
sudo command | sudo tee outputfile
<>—–root—–<>——-root——<>
The problem can be seen using a simple demonstration:

petur@laptop:/tmp$ sudo date > output
petur@laptop:/tmp$ ls -l
total 4
-rw-r--r-- 1 petur petur 30 2010-07-06 23:14 output
petur.petur is the owner of the output file.

petur@laptop:/tmp$ rm output


petur@laptop:/tmp$ sudo date | sudo tee output
Tue Jul 6 23:15:31 CEST 2010
petur@laptop:/tmp$ ls -l
total 4
-rw-r--r-- 1 root root 30 2010-07-06 23:15 output
root.root is the owner of the output file.
[ad#Google Adsense-1]

sudo redirection

We are faced with a problem when trying to use redirection with sudo, as the second part of the command is not executed with root privileges.
sudo command > outputfile
<>—-root——<>—user—<>
The solution is to use;
‘sudo tee’ instead of the ‘>’ operator,
‘sudo tee -a’ instead of the ‘>>’ operator.
sudo command | sudo tee outputfile
<>—–root—–<>——-root——<>
The problem can be seen using a simple demonstration:

petur@laptop:/tmp$ sudo date > output
petur@laptop:/tmp$ ls -l
total 4
-rw-r--r-- 1 petur petur 30 2010-07-06 23:14 output
petur.petur is the owner of the output file.

petur@laptop:/tmp$ rm output


petur@laptop:/tmp$ sudo date | sudo tee output
Tue Jul 6 23:15:31 CEST 2010
petur@laptop:/tmp$ ls -l
total 4
-rw-r--r-- 1 root root 30 2010-07-06 23:15 output
root.root is the owner of the output file.

Execute commands on a firewalled remote machine using Dropbox

I use dropbox to backup data offsite and sync it between my other computers.
THIS LINK points to a video explaining how dropbox it works.
One of those machines is my personal computer at campus.
It’s behind NAT/firewall so remote access is out of the question.
I figured I could use dropbox to execute commands on it remotely, so I made a bash script for the job.

#!/bin/bash
#
# Pétur Ingi Egilsson #
INPUTDIR=/home/petur/Dropbox/petur-laptop/input/
OUTPUTFILE=/home/petur/Dropbox/petur-laptop/output
for i in `ls $INPUTDIR`;
do
chmod +x $INPUTDIR$i;
echo $i - `date` >> $OUTPUTFILE;
/bin/bash $INPUTDIR$i >> $OUTPUTFILE;
rm $INPUTDIR$i
done

It executes all the bash scripts uploaded to the /home/petur/Dropbox/petur-laptop/input/ directory, be it a single line or a complex script and redirects the output to the /home/petur/Dropbox/petur-laptop/output file and then deletes the script so it won’t get executed again.
Add the script to crontab and make it run every minute or so.

Sending emails with Dropbox using mutt

Move any file into the ~/Dropbox/muttjobs/ folder and name it recipient@server.xyz{filename and the file will be emailed to the recipient.
On the ‘server’ side have this script running as a cronjob every 5 minutes.
Ps. whitespaces are not allowed in the filename and mutt must ofcourse be properly configured.

#!/bin/bash
MUTTJOBS="/home/petur/Dropbox/muttjobs/"
MUTTTMP="/tmp/"
for i in `ls $MUTTJOBS`;
do
recipient=`echo $i|cut -d{ -f1`;
data=`echo $i|cut -d{ -f2`;
mv $MUTTJOBS$i $MUTTTMP$data;
echo "sent via dropbox"|/usr/bin/mutt $recipient -s "filename: $data" -a $MUTTTMP$data;
rm $MUTTTMP$data;
done;

How-to: Limit the CPU% on a process in Ubuntu 10.04

I have two danish dictionaries I run with wine. They seam to be very CPU hungry for some reason, this causes the cpu fan to run to at 100% and the laptop gets very hot and noisy!
cpulimit is a nice program which can be used in order to place a limit on the cpu% a process gets.
Unlike nice, it can suffocate the process so it appears to be running on a much slower CPU. This is NOT the same as changing the priority or renice-ing the PID, as that will not limit the process on a free cpu.
This solves both my fan-noise and the heat problem.
cpulimit is in the official repos & it’s man page is pretty straight forward ( takes less than a minute to read throe. )
Below are two screenshots, before and after, showing it in action.
(click to zoom)
Before

After

How-to: John the Ripper on a Ubuntu 10.04 MPI Cluster

[ad#Banner]

In this PDF file:[ENGLISH] [ICELANDIC] i show step-by-step how you can setup your own “Super computer cluster” using Ubuntu MPI Cluster from multiple machines with the goal of bruteforcing strong encrypted passwords with John the Ripper for academic purposes.
Owners of quad core machines will also benefit from my paper as the “john” binaries found in the Ubuntu Repositories are compiled to run on only one core.
I managed to decrease the time required to crack password hashes at home to a fraction (9% of the original time) using my 3 computers with this setup.
The paper is meant to be plain and simple aimed towards the average user, thus i choose not to implement NIS, NFS, BIND, and other more complex technologies.
A student should be able to setup and play with a computer cluster system at home without spend days reading through Linux systems-administrators books and manuals.
I make use of Ubuntu 10.04 as it is the most commonly used available Linux distribution today.
I suggest “MPI Programming” as the google keyword for those interested in learning how-to write programs for such systems.
If you have any suggestions, problems, comments or would like to contribute to this document leave a comment or email me.
Enjoy.
[ad#Banner]

Linux how-to: ‘Shifting’ to a secondary keyboard layout.

The Danish language makes use of two letters [åÅ] and [øØ] which are not on the Icelandic keyboard.
I’ve tried to learn the Danish layout but I kept making errors and had a hard time remembering where symbols like ‘+<>;:!”#$%&/()=@ are located.
Having to switch permanently between keyboard layouts all the time with key combinations (Windows way of doing things) such as alt+shift is tiresome!
I was making too many typos and to many errors, I guess my muscle memory is just too strong!
It turns out that there’s a very easy way to make use of the Danish layout on Linux.
I never use the CAPS-LOCK key so I configured it to act a SHIFT-to-Danish-layout-while-pressed key!
Here is how:

ð is located on the Icelandic layout where å is to be found on the Danish layout.
‘ is located where ø is to be found.
CAPS+ð makes å
CAPS+shift+ð makes Å
CAPS+’ makes ø
CAPS+Shift+’ makes Ø
Beeing able to type on my native keyboard layout, using the Danish letters when needed means no learning curve, no confusion and no evil typos!
I believe this is something Microsoft Windows does not have.

Download YouTube Music Videos to MP3 files on Linux

youtube2mp3 downloads YouTube videos and saves them as .mp3 files.
Recommended The .deb will automatically solve dependencies and place a launcher under Sounds&Video
Download for Ubuntu (.deb)

Advanced The script can also be downloaded and launched from the command line, make sure you manually solve the dependencies.
Download for Linux (bash)

After installing, the program can be found under “Applications –> Sounds & Video –> Youtube 2 MP3”
After the application has been launched the following window will appear.
Simply copy the complete URL of the video you want and paste it into the textbox.



In this step you must choose where to save the mp3 file.
I’ll call mine song-name.mp3



Now the program will launch the download process in the background.
This can take a few minutes depending on the speed of your connection.



After a while this window should appear and your new .mp3 is in place.





If for some reasons the program fails, launch it from the command line and paste the output here as a comment or email it to me:  petur \at\ petur.eu.
Applications –> Terminal.
Type in “youtube2mp3” without the quotation marks and hit the enter key.