Update: Change to your Favorite directories on the bash shell by scripting ‘cd’

I’m sick and tired of having to remember and ‘cd’ long paths.
I decided to create my own console based Favorites-script which makes use of a definition file which is easy to change.
This post updates http://www.petur.eu/blog/?p=175
“cd /home/petur/Documents/school/2010/fall/chemistry” becomes “cdf chemistry”
and “cd /var/log” becomes “cdf log”
Demonstration video:

The setup process is pretty straight forward, here we go (single user setup):
Append the following to:
~/.bashrc file (single user setup)
/etc/bash.bashrc (for all users)

function cdf() {
# Pétur Ingi Egilsson ( petur <@> petur.eu )
# http://www.petur.eu/blog/?p=175
# Stuart Rackham ( srackham <@> gmail.com )
# cdf (Change to favorites)
local aliasfile fullpath
if [ $# -eq 0 ]
echo Usage: cdf FAVORITE
return 1
fullpath=$(grep $1, $aliasfile|cut -d, -f2)
fullpath=$(eval "echo -n $fullpath")
if [ ${#fullpath} -ne 0 ]
cd $fullpath
echo "Error: '$1' has not been defined in $aliasfile"
echo -n "Do you want to edit the file? (y/n): "
read editFile
case $editFile in
if [ ! -n "$EDITOR" ]
# Use the nano editor because
# the EDITOR env has not been set.
nano $aliasfile
$EDITOR $aliasfile
echo "Please use y,Y,n or N."
exit 1

Save the following file as ~/.cdfrc

# Definition file for cdf
# format: name,/path/to/directoryetc,/etc

Do you have any comments?


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.

# Pétur Ingi Egilsson #
for i in `ls $INPUTDIR`;
chmod +x $INPUTDIR$i;
echo $i - `date` >> $OUTPUTFILE;
/bin/bash $INPUTDIR$i >> $OUTPUTFILE;

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.

for i in `ls $MUTTJOBS`;
recipient=`echo $i|cut -d{ -f1`;
data=`echo $i|cut -d{ -f2`;
echo "sent via dropbox"|/usr/bin/mutt $recipient -s "filename: $data" -a $MUTTTMP$data;
rm $MUTTTMP$data;

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.