Script to remove oldest file in a directory

I’ve created a script in order to manage the /var/spool/cups directory. I like saving cups spool files for as long as possible, but cups will only allow one to set the maximum spool files to save. It doesn’t allow one to set a minimum % free disk space. Here is the script. It monitors the % space used in a given path and if the % free space is below the set amount the script will delete the oldest file in the directory until the free space is below the % given. Here’s the code:
SPOOL_DIR="/var/spool/cups" #location of cups spool
MAX_USAGE="80" #maximum % disk space used 

while [[ $(df "$SPOOL_DIR" | tail -n1 | awk '{print $5}' | cut -d"%" -f1) -gt "$MAX_USAGE" ]] ; do
        ls -t $(find "$SPOOL_DIR" -maxdepth 1 -type f) | tail -n1 | xargs rm -v

Batch convert MKV to MP4 using ffmpeg

I had a bunch of files in mkv format that I needed to convert to mp4 format so that minidlna could serve them to my Xbox 360. Here’s how they can be converted in batch using ffmpeg.
for f in *.mkv; do 
ffmpeg -i "$fn.mkv" -vcodec copy -acodec aac -ac 2 -strict experimental "$fn.mp4";
I used the following pages as resources:

Transfer a block device (or a file) over the network via ssh using dd.

Today I was converting some local virtual machine storage from LVMs to .img files on remote host. One can copy block devices over the network using SSH with a command like this:
dd if=/dev/vg/logicalvolumehere bs=1500 | ssh user@remotehost dd of=/path/on/remote/host.img
… or one could pass it through gzip first to compress the data as it goes over the network.
dd if=/dev/vg/logicalvolumehere bs=1500 | gzip -c | ssh gzip -dc \| dd of=/path/on/remote/host.img
Running the transfer through gzip, I was able to get a speed of 16.6 MB/s or about 133 megabits/sec. over a 100 megabit network.

Simple WordPress plugin (include-file)

I may have created one of the simplest possible plugins for WordPress. I also have no doubt that this has probably been created before my multiple other people, but it was easier to create than evaluate the existing options out there. If you just want to download the plugin click here.

This plugin includes the contents of a file from a URL or path into a WordPress page or post using a shortcode. It would look like this in your post:

[include_file url='']

I’ve posted the source code below as it might serve as a good template to someone who wants to create their own plugin.

Plugin Name: include-file
Plugin URI:
Description: Includes the contents of a file at a given url in a post.
Version: 1
Author: Tyler Stafford <>
Author URI:

function tsIncludeFile($atts,$content=null,$code="") {
	$content = file_get_contents($atts['url']); 
	if ($content == true) {
		return $content;
	} else {
		return "An error occured retreiving " . $atts['url'];
	return $atts['url'];


Locked user profiles in Windows 7/Vista/2008

I’ve been experiencing this problem at work for over a year. After the system was up for an undetermined period of time, users who logged in would sometimes receive the following message.

You have been logged on with a temporary profile. You cannot access your files and files created in this profile will be deleted when you log off. To fix this, log off and try logging on later. Please see the event log for details or contact your system administrator.

This appears in the event log as event id 1502, 1515, and 1511.

I had tried to resolve the problem numerous times and was never able to find any answers better than “restart the system”. Not good enough. Then yesterday, I FINALLY found a thread which accurately identified the cause of the problem. Apparently, it’s Google Updater!

One poster on another thread solved the issue by uninstalling Google Updater, however, I didn’t want to go so far just yet. Instead, I disabled the scheduled tasks setup by Google and the Google Updater Service. I scheduled a restart on the server and, so far, I haven’t seen the locked profiles issue again.

Update: I did more testing on this and the solution is indeed to remove Google Updater. I re-enabled the “GoogleUpdateTaskMachineCore” and “GoogleUpdateTaskMachineUA” tasks, and things seem to be working fine.

Updates to my KVM backup script

I’ve been spending quite a bit of time refining the KVM backup script. I’ve added the ability for the script to snapshot the LVM block device and immediately restart the machine. I was also not able to find a way to get Windows guests to shutdown reliably. The guest will shutdown if a user is logged on, and if no user is logged on, but it will not shut down if a user is logged on and the user has locked the workstation. To workaround this I added the “-w” option to shutdown a windows guest using the “net rpc shutdown” command with samba. Check out the project on github.

Super simple automated image based virsh/kvm backup

Warning: file_get_contents( failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/content/55/8027255/html/ on line 12

At my workplace I use KVM as our primary virtualization solution with LVM volumes for each virtual hard disk. I have created a simple script to perform an image based backup of a guest using dd. This could be improved by setting a snapshot while the guest is down and then immediately bringing it back up, however, I use backuppc for file based backup of the data on each machine. So, I don’t feel the need to perform image based backups often enough that I can’t fit them in a normal maintenance period.

The script is posted below and at github

Update: I’ve changed this post so it will always include the latest version of the script from github

An error occured retreiving