Mount Windows SMB/CIFS Share with Linux

I'm setting up virtual machines again. This always means sharing files between host and guest. I basically follow this guide on the Ubuntu Forums, but I tweak it a little bit for permissions reasons. It goes something like this:

1. Install tools to mount a SMB/CIFS share
[code]sudo aptitude install smbfs[code]

2. Make a mount-point
[code]sudo mkdir /h[code]

3. Store credentials some place safe
[code]sudo vim /root/.smbcredentials[code]
and type them in the following format:
username=winusername
password=winpassword
Save and close.

4. Add a line to fstab so that we're mounted automatically
[code]sudo vim /etc/fstab[code]
At the end, add the following:
//netbiosname/sharename    /media/sharename        cifs    credentials=/root/.smbcredentials,iocharset=utf8,file_mode=0774,dir_mode=0774,gid=plugdev,uid=mainuser 0 0
This is where I deviate from the instructions. I use file permissions 0774 instead of 0777. Why? I don't like the would world screwing with my files (though they can poke if they need to). I also change the user-id so that the mounted files are owned by my main user. And I make plugdev the group so that any plugdevs can play with the files too. (This is helpful for daemons that don't run as my main user).

5. Test
Make mount process everything in /etc/fstab
[code]sudo mount -a[code]
Now browse through the mountpoint and see if it worked. Golden? You're done!


Colin

 

Edit:

That was all fine and dandy until my network shares stared dropping and failing to mount with message:

mount error(12): Cannot allocate memory

Yup, its a Windows problem. Tell windows to allocate more resouces for file sharing: http://alan.lamielle.net/2009/09/03/windows-7-nonpaged-pool-srv-error-2017

Speeding up audiobooks -- or an example of MPlayer usage and why it rocks

This Christmas I received a Googled: The End of the World as we Know it on no less than 12 CDs. If you think I am going to sit and listen to all 14 hours of those discs, you are sorely mistaken. Instead I will take advantage of the something Cross-Ex debaters have known since the dawn of time: people can understand the spoken word, even when accelerated to an absurd pace.

Mplayer Speeds sans the Chipmunks
I love MPlayer, the Linux everything player, for many reasons. One of them is the ScaleTempo audio filter. This filter allows you to speed up playback without increasing the pitch of the media. Get out a terminal and see it for yourself:

versus
mplayer -playlist http://www.bbc.co.uk/radio4/arts/ram/agoodread.ram -speed 1.5 -af scaletempo

Normally I would just play the audiobook in MPlayer (or SMPlayer, actually, since its a great frontend), but I want to listen to Googled on my mp3 player, which doesn't run mplayer. The solution? Have mplayer speed up the audio and generate mp3.

The Command
This command will play the audiobook the way I want it to sound
mplayer disc01.wav -speed 1.5 -af scaletempo

-speed sets a 1.5x multiplier on playback rate
-af scaletempo sets mplayer to use the scaletempo audio filter and avoid the chipmunk effect

But I don't to play the book, I want to convert it to another digital form.
mplayer disc01.wav -af scaletempo -speed 1.5 -ao pcm:file=disc2fast.wav

-ao pcm:file=disc2fast.wav Send audio output to the fake PCM device instead of your speakers. Result: a wav file!

Viola, a static audio file sped up 1.5 times. Now I just convert that to an mp3, load to my player, and go!

Colin

Note: Since there were 12 files to process, I didn't do this speed each up manually. Instead I grabbed a script from http://gimpel.gi.funpic.de/wiki/index.php?title=Howto:convert_aac/mp4_to_wav/mp3/ogg_on_Linux and modified it to speed up input files 1.5 times.

audio2mp3_1.5x
#! /bin/bash
#
# Converts an Audio file to a MP3, speeds it up 1.5x, and adds an ID3 tag.
#
# Usage: audio2mp3_1.5x infile [outfile]
#
IFS=";" title_author=(`mplayer -vc null -vo null -af extrastereo=1.5 -af scaletempo -speed 1.5 -ao pcm:fast -ao pcm "$1" -ao pcm:file="$1.wav" 2>&1 | awk -F: 'BEGIN { ORS = ";" } ; $1 ~ /name|author/ { print $2 }'`)
author=${title_author[0]}
title=${title_author[1]}
echo "Author: $author"
echo "Title: $title"
lame "$1".wav "$2" --tt "$title" --ta "$author"
rm "$1".wav 

Make sure it is marked executable!

Ripping audiobooks in linux? Its as easy as ABCDE!

I received Googled by Ken Auletta for Christmas and don't feel like bringing all 12 discs back to college with me. Luckily, ripping each disc as a single audio file couldn't be easier in linux, the trick is abcde, a great program that acts as puppetmaster for a bunch of other programs (cdparanoia, cdda2wav, dagrab, flac, lame, faac, id3v2, etc, etc). In otherwords, it does all the work and keeps life simple

abcde_a435_large.jpg

I'm using this command on each disc:
abcde -1 -N -o mp3:"-b 128"

That is:
-1    Rip the disc to a single file
-N    "Non-interactive" aka "piss-off mode." Don't bother me with questions, the CDDB info you find is just fine
-o mp3:"-b 128"    Output an mp3 file and tell lame that I want 128 kbps

Sadly, there is no CDDB info for Googled, so I have to rename and edit metadata manually, but hey, not to bad.

Oh, if you're running ubuntu, get abcde on your system by running this command:
sudo aptitude install id3v2 lame abcde

Colin

More backups scripts

Writing backup scripts for UVC.

Using a lot of Bash scripting resources. The Gentoo community has created an excellent set of scripting cheat sheets:
http://devmanual.gentoo.org/tools-reference/bash/index.html

Changing Case
I think there is some way to do this with Bash parameter expansion, but I haven't found it yet, so I use tr to do the job

lower1=`echo $1 | tr '[:upper:]' '[:lower:]'`

Okay, looked a little more, looks like Bash v4 can do case change parameter expansions, but I'm at version 3.1.17, so I'll have to wait :P

Directory Size
I only list dir sizes on the command line occasionally, and always forget

du -hs

-h is human readable
-s is summary

Grep Exclude
Useful

grep -v ...

I'm also using the -i flag (ignore case) even though the cases all came from the same host on linux and should match.

Note: df is used to find free space instead of space consumed.

A Good Find
The -type argument to find is highly useful. Though there are several options (fifo, link, socket, etc), these two are probably the most useful

find . -type d</br>find . -type f

(directory find and file find, respectively)

A Giant Argument
Argument separation has become a huge problem for my backup scripts. I use grep to create a list of files, but some have spaces. When I pass this list to tar, Bash decides to separate the filenames. No combination of quoting, or escape characters has worked to solve the issue.

Solution: change the way Bash interprets commands.

$IFS -- the Internal Field Separator
defaults to whitespace (newline, tabs, spaces, etc)
Set it to only pay attention to newlines and the spaces make it tar unscathed

IFS=$newline
tar
some
stuff
# separate w/ newlines
unset IFS 

These pages are good resources:
http://tldp.org/LDP/abs/html/internalvariables.html
http://mindspill.net/computing/linux-notes/using-the-bash-ifs-variable-to-make-for-loops-split-with-non-whitespace-characters.html

I am throughly done with shell scripting for a long time. Next time I'm using python!

Colin

Backup Wordpress 5.5

Trying it out with this plugin:

Not verified for WordPress 2.9.1r. Problem right now is that it cannot send the full backups by email because the PHP mail function dies.

Another option would be to backup to "the cloud." Skydrive is free, so thats a nice option. Otherwise Amazon S3 is very affordable.

This plugin
seems to do the trick for sql backup, but I don't know about content backup.

For now I'm going to try and separate the backup operations into smaller chunks so that we can just use gmail. I suspect that all the large files are stored in the theme directory.

Mission Status: Failure
Looks like this wordpress plugin doesn't allow me to specify particular directories to backup or exclude. Rather, I can exclude directories, but I cannot setup multiple backups so that everything is covered.

Next Approach: Cron-Job to upload files via FTP to g.ho.st
Nope that doesn't work either. Bluehost doesn't have working FTP. cUrl doesn't work, wput doesn't work, ftp doesn't work. They all fail to connect. Works fine on dreamhost!

Next Approach: Split files with a cron job and email using shell / php function
Using the split command:
split -b 24m -d big.tar.gz out.suffix

Actually sending
Sending is another chore. It can be done with the unix mail command, but decided that would be a bit too much work (you have to uuencode, and I don't think it can be downloaded as an attachment).

There was a mail-file command on the host, but it didn't work, complained about a linux command called "no" not existing. Dunno how I'm supposed to figure out what "no" is.

So I compiled mutt instead and am following these instructions:
the form I care about is:
mutt -s "Subject line" -a /path/to/attachment recepient@email.com < /tmp/message/body

 But that didn't work by default on Bluehost, I had to make some changes to ~/.muttrc
Following the suggestion of this thread: http://www.bluehostforum.com/showthread.php?t=16623
I added 
set sendmail = /usr/sbin/sendmail
to ~/.muttrc , no works! Can even send large, 25Mb files!

Bash hacking
To perform the split, mail, etc operations required a lot of bash hacking. Some sites proved indispensible:
panix.com/~elflord/ http://posterous.com/javascripts/tiny_mce/themes/<script type="> advanced/langs/en.js?1262837506" type="text/javascript"> unix/grep.html" target="_blank"& http://posterous.com/javascripts/tiny_mce/themes/advanced/langs/en.js?1262837506" type="text/javascript"> gt;http://www.panix.com/~elflord/unix/grep.html

Script Done
Seems to work, script looks something like this:
#!/bin/bash
echo "##################"
echo "Greetings humans!"
echo "    - backupsNeverSayNeverBlog.sh"
echo
echo "# @author: Colin Zwiebel"
echo "# @created: 6 Dec 09"
echo "#"
echo "# Backups the contents of the neversaynever.net blog"
echo "# Grabs the full backup tar, splits it into mailable sizes and send it to our "
echo "# gmail backup account."

echo "====Setting up constants"
target_email="backup@neversaynever.net"
backup_file_dir=~/public_html/wp-content/backup/
tmp_directory=~/tmp/
tmp_subdir=backup_split/

echo "====Getting the name of the most recent backup file"
latest_backup_tar=`ls -1 --indicator-style=none $backup_file_dir*full* | tail -n 1`
echo " - its named: $latest_backup_tar"

echo "====Isolating the name of the backup file (without path)"
latest_backup_tar_fn_only=`echo "$latest_backup_tar" | grep -oiE '/[[:digit:]]{4}.+\.tar\.gz$'`
latest_backup_tar_fn_only=${latest_backup_tar_fn_only:1}
echo " - filename alone: $latest_backup_tar_fn_only"

echo "====Clearing out temp space for file splitting"
clear_cmd="rm -rf $tmp_directory$tmp_subdir"
echo " - $clear_cmd"
#debug
#$clear_cmd
mkdir_cmd="mkdir $tmp_directory${tmp_subdir%%/}"
echo " - $mkdir_cmd"
$mkdir_cmd

echo "====Splitting the full backup into 25mB chunks"
split_cmd="split -d -b 25m $latest_backup_tar $tmp_directory$tmp_subdir$latest_backup_tar_fn_only"
echo " - $split_cmd"
#DEBUG
#$split_cmd

echo "====Getting number and name of backup segments"
ls_cmd="ls -1 --indicator-style=none $tmp_directory$tmp_subdir$latest_backup_tar_fn_only*"
#echo " - $ls_cmd"
parts=`$ls_cmd`

echo " - We found these segments:"
for f in $parts
do
 echo "   * $f"
done

echo "====Emailing backup segments"
echo " - To: $target_email"
timestamp=`date`
subject="NeverSayNever Backup Script: Full Backup on $timestamp"
echo " - Subject: $subject"
message="NeverSayNever Backup Script performing a full backup of NeverSayNever Wordpress
Timestamp: $timestamp

--The following backup file parts will be tranferred as separate messages:
$parts"
echo " --- Message: ---
$message
 --- End Message ---"

for f in $parts
do
 mail_cmd="mutt -s \"$subject\" -a $f $target_email"
 echo " - about to send $f"
 echo "$message" | $mail_cmd
 echo " - send command executed"
done

echo "====Script done, c'ya folks!!!"

but... still need to get the cron jobs setup.

Oup, there done. More problems (naturally). Cron runs as root (whee) and so it didn't have settings from my .bashrc (namely the $PATH stuff). Using fully qualified path names did the trick.

Bluehost SVN

Bluehost doesn't have a "goodie"/easyinstall for SVN like DreamHost does. So I'm doing this instead:

Setup svn subdomain, first

Then I discovered that gunzip and gzip, and all that other *zip crap were broken on Bluehost (cyclic symlinks?). Solution, I grabbed gzip and gunzip from the box Alight Learning operates on and pulled them into ~/bin

Then a change to .bashrc, now reads
# User specific aliases and functions
PATH=$HOME/bin:$PATH 
 
export SVN_EDITOR=vim
 
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

(gotta use VIM if we're using SVN!)

but I had to change the version of apr and apr-utils to match the current newest (and actually available): 1.3.9

But I didn't get very far through through the instructions because I stopped at step 4.2 (create a keypair)

Recapping: I created an ssh private / public key:
cd
ssh-keygen -b 1024 -t dsa -f colinkey 

and shuffled things around
mkdir ~/.ssh
chmod 700 ~/.ssh
cat mykey.pub >> ~/.ssh/authorized_keys 

I did download the private key to my computer (colinkey) but I then started reading someone else's instructions on svn-ssh tunneling:

The important bit was to add the "command" line to authorized_keys
command="svnserve -t -r /home/neversa2/svn/ --tunnel-user=colin",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty TYPE KEY COMMENT
before the appropriate public key

then I edited ~/.subversion/config on my local computer and added the following line to the [tunnels] section
zwi = ssh -i ~/.keys/colinkey

then a simple
svn co svn+zwi://neversaynever.net/neversaynever
got me checking in and out as user colin