Saturday, 13 August 2011

HOW-TO: Convert .aac .m4a file to .mp3

You first extract the audio from the .mp4 or .m4a to .wav using faad. Then convert the .wav to .mp3

You need faad2 and lame installed.

$ faad foobar.m4a       # to convert to wav
$ lame foobar.wav foobar.mp3          # to convert to mp3

Friday, 5 August 2011

HOW-TO: Email notification of SFTP file upload

Following on from my post, 'HOW-TO: Chrooted SFTP only access' I wanted to find a way to get an email notification of when a client had uploaded a file to my work's SFTP area. I had Sendmail already installed.

Each client has their own subdirectory under /home/sftp/ and I wanted to monitor them all and trigger an email when a new file was created.

Ok, I don't know how much use this will be to others but I am just going to throw down what I did to achieve what I wanted. These are personal notes and use them at your peril.

sudo apt-get install iwatch

installs iWatch, written in Perl and based on inotify, a file change notification system, a kernel feature that allows applications to request the monitoring of a set of files against a list of events.

sudo touch /etc/init.d/sftp-iwatch

creates an empty file. I edited the file and typed

iwatch -r -e create -c "(w;ps -ef)|/home/david/ %f '$($(which date))'" /home/sftp >> /dev/null 2>&1 &

which basically executes a script /home/david/ when a new file is created under /home/sftp/.

# 20110723 David Humble

DATE=$($(which date))
SUBJECT="File upload notification"

echo "Date: $DATE" > /var/upload.txt
echo "To: $EMAIL" >> /var/upload.txt
echo "From: $FROM">>/var/upload.txt
echo "Subject: $SUBJECT">>/var/upload.txt
echo "New file $FILE created at $CREATED on aadfiler SFTP Server.">>/var/upload.txt
echo ".">>/var/upload.txt

cat /var/upload.txt | /usr/sbin/sendmail -t

sudo chmod +x /etc/init.d/sftp-iwatch
sudo chmod +x /home/david/

makes both files executable.

cd /etc/init.d
update-rc.d sftp-iwatch defaults

Adds sftp-iwatch to the servers startup processes.

now you can manually start sftp-iwatch by typing
sudo /etc/init.d/sftp-iwatch

Now whenever a client uploads a file to any subdirectory of /home/sftp/ I get a notification thus:
Date: Wed Aug 3 16:27:02 BST 2011
From: aadfiler@xxx.local
Subject: File upload notification

New file /home/sftp/clientsname/upload/AAD013 GE eNewsletter Day 3.csv created at Sat Jul 23 13:36:37 BST 2011 on aadfiler SFTP Server.


Categories: How-To, Linux, OS, Open-SSH, SFTP server, Chrooted SFTP only access
Tags: kde, ubuntu server, Linux, open-ssh, chroot, sftp, File upload email notification, iwatch, notify, dnotify