Friday, April 4, 2008

tunnel x11 through ssh

I've read about this a lot all over the internet, but I've found something of a mixed bag of info. Rather than try to remember where these sites were, I guess I'll just stick a brief how-to up here:

Note: This is best aimed at people who already ssh into their machine.

  • Make sure that your /etc/ssh/sshd_config (or where-ever this stuff hides on your flavor of linux) has these lines:
AllowTcpForwarding yes
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalHost yes
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
  • Get xming or something similar. (xming is the free one that seems to work. I'm not sure about the others because I'm too cheap to go out and buy an xserver for windows so I can connect to my free xserver on my free operating system, using other free tools to connect, via the free (for now) internet).
    • You can easily install this onto a usb-drive and run it portably, just by selecting the drive as the install directory. It works rather well, especially if you have a good internet connection.
  • Once that's done, you should be able to log into it(ensure that you have x11 tunneling enabled on your putty or ssh program.

Sunday, February 10, 2008

shuffled playlist

Well, I've been lazy on this blog. I'm not surprised at this, as the number of online writing assignments for school has now reached 4 blogs and 3 wiki-projects.
I enjoy working with them and reading my classmates' work, but by the end of the day I just don't care to write or read anything else.
Because of this, I've been a little bit slow on the home-brew things of late.
I have been working on a phpMyAdmin, Ruby on Rails,(maybe) CVS arrangement on my little server and it's been working out well.
However, I've done nothing beyond the basic instructions for installation on their respective websites, so there is little useful information that I can share there.

No, what I wanted to write today was this little script I have that'll create a playlist of n tracks, fill it random from the large library I have and play it for me:

for i in /media/hda3/music/*/*/*.mp3;
do
trailer[x]=$i;
let "x +=1";
done;

cmdstr="";
total = $# > 0 ? $0 : 20;

for (( j = 0 ; j <= total; j++ )) do trailer[y]="${trailer[$y]}"; cmdstr+=" ${trailer[$y]} "; cmdstr+="^~" done ; echo $cmdstr | tr -s "^~" "\n" > shuffledList
mplayer -playlist shuffledList;


Now, this thing looks hideous. I found a script while wandering around trying to do this a while ago that was marked as non-functional but the guy said he thought he was "close". I downloaded it and couldn't figure it out. Upon revisiting it this evening, I tinkered and found a sub-standard, though functional, way of fixing it. I would credit the original author, but it was on some forum somewhere and I'm afraid I do not recall where. I have altered it significantly, though, as his would use the entirety of the directory(which was unsuitable for me, as mplayer whined at me when I tried to just do mplayer */*/*.mp3 , saying that I had too many arguments).

This looks rather had to figure out, but it essentially takes the entirety of my directory and stuffs it into an array, which it then randomly parses through and creates a big string containing all the pathnames. I could not, for the life of me, get it to output line-breaks, so I had to do this idiotic workaround where it takes the weird little string I have up there: ^~ and turns it into a linebreak with the translator. It then outputs the whole thing into a file and has mplayer play it.
I'm sure there's a more efficient way doing this, but this works and I like it.

Sunday, January 27, 2008

irritating script

I've just hooked up a pair of speakers to the server-box which happens to exist in my living room.
note: This placement is due to primarily to poor planing on the apartment layout and our furniture choices, forcing me to keep the wireless router, cable modem and server(which is a small box, fortunately) all under the coffee table which sits between two chairs.

Bottom line: I now have sound coming out of this box, but the speakers are hidden under the table.
I doubt that it'll work very well, but I can now make sounds come out from (apparently) nowhere.
so I wrote this script:

iterate=5
wait=3
if [ $# = 2 ]
then
iterate=$1
wait=$2
fi
for (( i = 0 ; i < $iterate ; i++ ))
do
sleep $wait
mplayer cricket_1.wav
done

which plays a sound file repeatedly, based on the arguments that you give it. If none are supplied, it'll just play defaults of a 3 second wait, five times over.
This could get creepy, if I do it right.
Also, I can now use it to play my music library through some reasonable speakers

little note:

One of surely many future little posts about nifty commands I've found through wandering around trying to learn how to do stuff.


I Was trying to figure out how to send a command to my server via ssh that would continue to run after I logged out.

Super simple, right?

Well, I had a hell of a time getting it to keep going after I logged off. I believe I was doing some other stuff wrong, but it was frustrating when you don't understand much of what you're doing, yet you're doing it anyway!

Long story short, I learned of a few commands:
at
cron
nohup

at is for scheduling specific commands at a certain time. You can use it to perform a command at a later time. I couldn't get this to work, but I realized that it wasn't what I wanted anyway. It does seem rather interesting though, you just type at 12:00 and it'll prompt you to enter commands that it will perform at that time. hint: you end the list with ctrl-d. the time can be anything: now + 1 hour , teatime , midnight + 10 minutes .

cron is like at, but it keeps a list and performs them routinely. it works by making a schedule of commands to run at specific times at specific intervals. I didn't look into this at all, because I only wanted to run this one command once.

nohup stands for "ignore hangups" ... somehow. It ignores the minor detail of you logging off and allows the command to continue to run unabated. I had some weird issues with this, but I believe it was just a sudo or something that I needed. It also might have been a space issue, since I wasn't paying attention to where I was running this command.

essentially, I settled on nohup for the task at hand, but I'm sure I'll come across a need for the others.
the command in question? downloading a large torrent, of course:

sudo nohup btdownloadheadless highlyImportantTorrentFile


silly, I suppose, but I learned some stuff from it.

Monday, January 21, 2008

Code Snippets

Long weekend: Fun, Relaxation, Homework, etc.

Heres that code I promised:

#Little script to automatically encode .aiff files to mp3s
#It also takes the directories around it to figure out
# artist and album info (I'm too lazy to keep looking for a
# means of taking them from the .aiff files
#It then hides the original aiff file by affixing a . to th beginning

#iterates through the working directory looking for .aiff files
#(In several instances, I had some files that were just .aif
# and others that were .aiff, so I just stuck the wildcard on the end
dir="*.aif*"
if [ $1 = "all" ]
then
dir="*/*/*.aif*"
fi

for file in $dir
do

#takes the full path and chops everything but the working directory itself
# the ## represent taking the longest suitable string from the LEFT side

temp=${file##/*/}
album=${temp%/*}

#takes the album off of the front, essentially

temp=${file%/*/*}

#takes the rest of the path off, hopefully keeping the artist

artist=${temp##/*/}

#checks to see if the user selected to automatically pick out
# the track number from the beginning of the filename
num=""
if [ $# -gt 0 ] && [ $1 = "trackno" ] || [ $1 = "all" ]
then
temp=${file##*/}
num="--tn ${temp%%\ *}"
fi

if [ $# -lt 2 ]
then
#runs the sublimely simple lame encoder command with 192 kbps bitrate
lame -h -b 192 "$file" "${file%.*}.mp3" --ta "$artist" --tl "$album" $num
#if the user supplies "album", it assumes that the only relevant directory
#corresponds to the album name
elif [ $2 = "album" ]
then
lame -h -b 192 "$file" "${file%.*}.mp3" --tl "$album" $num
#if the user supplies "artist", it assumes that the only relevant directory
#corresponds to the artist name
elif [ $2 = "artist" ]
then
lame -h -b 192 "$file" "${file%.*}.mp3" --ta "$album" $num
else
echo "incorrect parameters"
fi
#these two below are so that apache, obsidianmusic and amarok can work
# with the files to their hearts content

sudo chmod 777 "${file%.*}.mp3"
sudo chown dhcp "${file%.*}.mp3"

#Hides the old aiff files so that it doesn't do them twice.
mv "$file" "${file%/*}/.${file##*/}"

done
Its got a few comments in there, but I had a bad habit of adding crap and forgetting to document it.
More descriptions on it later!

Wednesday, January 16, 2008

Adventures in Musical Incompatibility

Naturally, the day I decide to start a blog is the day right before I start getting busy with assorted assignments.

Nevertheless, I have some interesting things lying around (physically, digitally and mentally) that I believe warrant posting:

The premise

I have a large batch of .aif files that I got from a family member. These are some of his CDs, ripped and encoded on his Mac. Some are his own tracks, some are music that I like that he happened to have lying around, so he just dumped a few hundred of them onto an external hard drive I had lying around and handed them over. It wasn't until I tried to listen to them in Amarok (One of the default music players on Ubuntu) that I realized it was an incompatible format. naturally, this meant that they were practically invisible to the Amarok-based MySQL database and, conversely, the php frontend that employed it.

This frustrated me at first, but I quickly realized that .aif was simply an unencoded raw file with the music on it, meaning that converting to mp3s should be as easy as running a command to encode them and boom, presto-chango: Relatively compatible mp3s at my fingertips.

It wasn't until I actually sat down and tried to figure out the best way to do it that I settled on some sort of shell script to perform this relatively simple task.

I now had two tasks: learn enough shell scripting to set this up and find the right command to encode .aif to .mp3

Tuesday, January 15, 2008

An Interesting Endeavor

I, a college-level computer-science student, have reached a conclusion:
I can't possibly be the only one who gets overwhelmed by the amazing amount of information on the internet.

I've been working with computers for-bloody-ever, and I'm getting into more and more obscure things as I go, now. One of the things I've noticed as I wander into the (relatively) deep, dark corners of computer-fiddling is that it gets harder and harder to find a centralized how-to manual.

Just this last weekend, I learned some basic shell-scripting syntax (in bash, for Linux) for the sole purpose of transferring some music from .aif, which is incompatible with my complicated setup (that I'll probably get into as I get going with this blog), into mp3s.

Simple, right?

Well, yes and no. One of the first things I'll be talking about here is what trials and tribulations I went through, along with my code and the little bits of info I picked up along the way.

At least I'll have a centralized help-file for my own uses, if nobody else enjoys it.