HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Programming/Scripts (http://www.howtoforge.com/forums/forumdisplay.php?f=7)
-   -   Convert scan-2-ftp into scan-2-email (http://www.howtoforge.com/forums/showthread.php?t=42262)

sjau 29th December 2009 21:11

Convert scan-2-ftp into scan-2-email
 
Hi there

In my place I setup today a network printer in such a way, that I can scan-to-email while the printer itself supports only scan-2-ftp.

The printer itself provides a custom of scan profile that can easily customized. In that way I could setup for everyone an own profile and hence custom login data to the ftp server.

The ftp server itself is a small "home-made" business server. It serves the webpage and acts as email server. So on that server I setup proftpd with virtual users on mysql according to the howtos in here.

With that combination I was able to provide for each scan-to-ftp profile on the printer a custom ftp mail account with a custom dir.

What I needed then was a script that regurarly checks the ftp folders and sends an email if a new file is there.

I used this script here that i wrote:
Code:

#!/bin/bash

user_arr[1]="user1"
user_arr[2]="user2"
user_arr[3]="user3"
user_arr[4]="user4"
user_arr[5]="user5"

email_arr[1]="user1@domain.com"
email_arr[2]="user2@domain.com"
email_arr[3]="user3@domain.com"
email_arr[4]="user4@domain.com"
email_arr[5]="user5@domain.com"

basefolder='/data/ftp'
emailtext="$basefolder/emailtext"

for I in ${!user_arr[*]}
do
        user="${user_arr[$I]}"
        email="${email_arr[$I]}"
        cd $basefolder/$user
        pwd
        for F in `ls`
        do
                VAL=`lsof $basefolder/$user/$F`
                if [ -z $VAL ]
                then
                        echo $F
                        echo $email
                        mutt -s "Scanner - Dokumente" -a $F $email < $emailtext
                        rm $F
                fi
        done
done

rm $basefolder/sent

And then I run that every minute by cron.

I have tested this a little today and it works quite well. However I'm not sure if that script above is good. The only way I could think of to check if a new document has been finished transferring from the printer to the server is by the use of the lsof command.

If you have better suggestions I'd be glad to hear that.

falko 30th December 2009 15:48

Maybe it's also possible to use the find command, as done in this tutorial: http://www.howtoforge.com/back_up_my..._interruptions

sjau 30th December 2009 18:38

thx, I'll have a look there :)


All times are GMT +2. The time now is 06:28.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.