Author Archives: Alex Forbes

Creating samba share in Nautilus: ‘net usershare’ returned error 255

I was having this problem on Ubuntu 12.04 (precise), but most of the Google results pointed to a bug in Hardy. However there are other causes of this problem.

In my case it was a previously-created share with a different user ID – Nautilus couldn’t create the share because there was already a share file with the same name owned by a different user.

The directory is /var/lib/samba/usershares. You should already have write access assuming you’re a member of the sambashare group (which the gui should handle for you), so all that remains to be done is remove the offending share with the same name as the one you’re trying to create.

alex@al4:~$ cd /var/lib/samba/usershares/
alex@al4:/var/lib/samba/usershares$ ls -lah
total 16K
drwxrwx--T 2 root       sambashare 4.0K Jul 25 12:33 .
drwxr-xr-x 5 root       root       4.0K May  1 10:40 ..
-rw-r--r-- 1 2046297271 2046296576  142 Oct 25  2011 music
-rw-r--r-- 1 2046297271 2046296576  128 Feb  7 17:13 videos
alex@al4:/var/lib/samba/usershares$ sudo rm music
[sudo] password for alex:
alex@al4:/var/lib/samba/usershares$ sudo rm videos
alex@al4:/var/lib/samba/usershares$

After doing the above, Nautilus was able to recreate the shares without trouble.

Percona Monitoring Plugins for Cacti and Redis auth

In implementing the Percona Monitoring Plugins for Redis on our Cacti server we discovered that they don’t support authentication. This creates a problem when your servers require authentication to issue the “INFO” command.

The Percona templates use ss_get_by_ssh.php to fetch the data, and there are functions specific to Redis in this file. So I added a variable to store the password, and modified the redis_get function to run an AUTH command on the socket before INFO.
Continue reading

Photo workflow script

After trying several photo management tools I’ve concluded that the best way to manage a photo library is the simplest – copy the files yourself and name the directory.

I also often shoot in RAW+JPG mode on my camera and like to keep the files separate to make viewing saner, so under each event directory I will have a RAW and JPG directory as well.

After downloading, the first step is always to delete the photos that didn’t come out. With both raw and jpeg files to delete this process is a bit of a pain, especially when they’re in separate directories, so I wrote a script that deletes the raw file when the jpg is missing. That way I can simply browse through the JPG directory with Eye of Gnome, delete the photos I don’t want, and the script handles cleanup of the RAW directory.

https://github.com/al4/scripts/blob/master/bash/rawdel.sh

The code is below but you should use the github link above in case it gets improved at some point in the future.

[shell]
#!/bin/bash

# rawdel.sh, a photo workflow script to delete raw files when the jpg has been removed
# By Alex Forbes
#
# I frequently shoot in RAW+JPG mode and when downloading from the camera I like to separate
# the raw and jpg files into separate directories. I then go through the jpg directory and
# delete the rejects. It is a pain to have to manually delete the corresponding raw files as
# well, so I wrote a script to do it for me.
#
# It simply removes RAW files from a directory when the corresponding JPG file has been removed.

# Set these
rawextn=”CR2″ # raw file extension (Canon is CR2)
rawdir=”./RAW” # directory where raw files reside
jpgdir=”./JPG” # directory where jpg files reside
# rawdir and jpgdir can be the same

# Working variables, leave as-is
list=”” # list of files that have been deleted
rawlist=”” # the list of raw files that we will delete
filecount=”” # number of files we will delete

# Operate on each raw file
for f in $(ls -1 $rawdir/*.$rawextn); do
# Corresponding JPG file is:
jpgfile=$(basename $f | sed “s/\.$rawextn$/.JPG/”)

# If this JPG file doesn’t exist
if [ ! -f $jpgdir/$jpgfile ]; then
# Add to our list of files that have been deleted
list=$(echo -e “${jpgfile} ${list}”)
fi
done

# Convert jpg filenames back to corresponding raw filenames
rawlist=$(echo ${list} | sed ‘s/\.JPG$/.CR2/g’)
filecount=$(echo -e ${rawlist}| awk ‘END{print NF}’)

if [ $filecount == 0 ]; then
echo “No files to delete”
exit 0
fi

echo -e “About to remove $filecount files:\n${rawlist}”
read -p “Continue? [Y/N] ” prompt

if [[ $prompt = “Y” || $prompt = “y” ]]; then
# Delete all files in the list
for f in ${rawlist}; do
rm -v $rawdir/$f
done
exit 0
else
echo -e “\nAborted.”
exit 1
fi
[/shell]

Intel wifi led blinking AGAIN on Ubuntu 12.04

I previously posted about this on previous versions of Ubuntu, but despite updating the instructions for 11.10 the instructions are once again obsolete. It seems Intel changes the name of its wifi kernel module every release…

On my Dell E4300 with “Intel Corporation WiFi Link 5100” (as reported by lspci), the module name is now “iwlwifi”. This means the kernel options you add to /etc/modprobe.d should be against this module rather than iwlcore (11.04) or iwlagn (11.10).

So the instructions once again:

$ sudo -i
# echo 'options iwlwifi led_mode=1' >> /etc/modprobe.d/wlan.conf
# modprobe -r iwlwifi && modprobe iwlwifi

Bear in mind that the second line removes the wifi kernel module temporarily which will disconnect your wifi. It should automatically reconnect, if not reboot.

I Sincerely Hope I Never Write a Script like this Again

This sort of stuff destroys your soul:
[shell]
#!/bin/bash
logfile=~/slave-watcher.log

while true; do
status=$(mysql –execute=”show slave status\G”|grep “Seconds_Behind_Master:”|awk ‘{print $2}’)

if [ $status == “NULL” ]; then
mysql –execute=”show slave status\G” | grep “Last_SQL_Error:” | tee -a $logfile
mysql –execute=”set global sql_slave_skip_counter=1; start slave;”
fi

sleep 1
done
[/shell]
What it’s doing is looking at MySQL’s slave status and skipping over any statement that causes an error. There are so many reasons why you should never do this, and I won’t go into detail on what necessitated it here, but you’ll be glad to know the slave I set this loose on was not in production!

Buying a PC Power Supply in the UK, January 2012

In the process of building my first desktop PC in about 4 years, I’ve come to realise that I no longer know anything about PC hardware. At one stage I considered myself, perhaps incorrectly, to be fairly knowledgeable about the subject of PC power supplies, even writing a PSU guide for a forum I used to frequent. Most of that guide is now irrelevant but looking back it wasn’t terrible advice for a newbie looking to buy a PSU at that time.
Continue reading

Viber battery life – an update

My impromptu post about Viber gained a little more attention than I thought it would, prompting a discussion about battery usage and even attracting a response from the Viber development team.

I’ve said it before and I’ll say it again, it was never a proper review, just a highly subjective and unscientific personal impression of the app! My main complaint was and remains that it looks like an iPhone app (I probably should have complained about the purple colour while I was at it).

They did ask that I test the new version (2.1.2), released on October 12, 2011, so naturally I feel as though I should test it in the same fashion as before. That is to say, open Android’s battery life screen after Viber has run for a while and take a screenshot. :)
Continue reading