Wednesday, June 24, 2009

HOWTO: Set the SSHD Idle Timeout

Here's something that I usually forget to change from the default and then get annoyed when my terminal hangs.
  1. As root open your sshd_config file in an editor.
    su -  
    vim /etc/ssh/sshd_config  

  2. Add the following lines.
     ClientAliveInterval 600  
     ClientAliveCountMax 3

  3. Restart the sshd process.
     service sshd restart
That's it. That will keep you logged in for 30 minutes at a time without activity. (600 seconds x 3)

Saturday, April 4, 2009

M3U Playlist Copy Script

A couple of months ago I picked up a Garmin Nuvi 760 on the cheap. As it turns out this great GPS unit can also play music quite well, especially for riding on the motorcycle. The only problem was there was no good way to get playlists on the device that I could find. Enter the following bash script. This script will read an m3u file, copy all associated mp3 files, and generate a new m3u file. Now all I have to do is specifiy m3u files that I exported from Mozilla Songbird and the path to the Garmin's SD card.

 # April 4, 2009  
 # Take an m3u file and copy all associated mp3 files  
 # to a destination directory and generate a new m3u.  
 # Used to copy m3u playlists from computer to Garmin.  
 if [ $# -lt 2 ]; then  
 echo "Usage: some.m3u /dst"  
 exit 0  
 # Read the m3u file into an array  
 declare -a M3U  
 exec 10<"$1"  
 let count=0  
 while read LINE <&10; do  
 exec 10>&-  
 # Determine the m3u's filename  
 if [[ $1 =~ [^/]*m3u ]]; then  
 # If playlist arleady exists, delete it  
 if [ -f "$m3u_path" ]; then  
 rm -f "$m3u_path"  
 # Loop through the m3u lines  
 while [ $i -lt ${#M3U[@]} ]; do  
 # The current line is a comment, do nothing with it  
 if [ ${M3U[$i]:0:1} = "#" ]; then  
 echo ${M3U[$i]} >> "$m3u_path"  
 #Current line is a path to an mp3 file  
 # Get the current songs filename  
 if [[ ${M3U[$i]} =~ [^/]*mp3 ]]; then  
 mpath=$( echo ${M3U[$i]} | tr -d '\r' )  
 # if the song doesn't exist, copy it to the desitnation folder  
 if [ -f "$2/$song" ]; then  
 echo File Exists -- $song  
 echo Copying -- $song  
 cp "$mpath" "$2/$song"  
 # Write the song in the m3u file  
 echo $song >> "$m3u_path"  
 echo "The regex for finding the song's filename is fraked up."  
 let i=i+1  
 exit 0  

In the middle of writing this I really started wondering why I used bash. Perl would've been a lot easier.

Wednesday, March 11, 2009

SVN+SSH Howto: Subversion Quick and Simple

Here's a quick and simple way to create a Subversion repository while maintaining security by using SSH and the filesystem permissions.
  1. Create users and add them to a group. There are a bunch of different ways to do this. I am only showing you how to create a group.
    groupadd svn-users

  2. Make a directory to house the repository.
    mkdir /var/lib/project

  3. Create the repository.
    svnadmin create /var/lib/project

  4. Change permissions to allow the group read/write access.
    cd /var/lib/project
    chgrp svn-users db db/transactions db/write-lock db/revs db/revprops hooks locks
    chmod 2770 db db/transactions db/revs db/revprops
    chmod 660 db/write-lock
    chmod 750 hooks
    chmod 770 locks
You can now have your users access the repository over SSH.


If your clients are on Windows, I recommend using TortoiseSVN.

Credit goes to the Carnival of Technology.