Register
It is currently Mon Sep 01, 2014 7:54 pm

Auto mount/rsync/detach script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Sun Jan 02, 2011 1:07 am   

Joined: Sun Jan 02, 2011 1:05 am
Posts: 1
Hi All,
I have got a box here running FreeNAS and have started to hack at
someone elses script to make it do what I want. In particular his
script was;
1) encrypting the USB attached device - which I dont need.
2) repeated beeping when finished (one long beep would be fine)
3) I dont know what the A16P echoing is all about
I am not quite there yet, and hope someone here can help. What I want
to do it:
1. Automount USB disk when plugged in
2. Rysnc certain directories
3. Dismount when finished
4. Send email with some sort of details (ie failure of 1,2,3 or 4, and
also upon success of 2 (rsync)).
So far this is what I have ended up with, some of the folders I have
hard coded.

Code:
#!/bin/bash -x
key_file=/temp/ukey.key
device=da${1//[a-z]/}
origin=/mnt/DATA/
target=/mnt/secret
echo ${device}
echo ${target}
_start() {
    if [ ! -f /var/run/${0##*/}.pid ];then
        echo $$ > /var/run/${0##*/}.pid
    else
        /usr/bin/logger "Error syncing $origin on $device";
        echo "A16P16A16P16A16P16CP8CP8CP8A16P16A16P16A16" > /dev/
speaker
        _finish;
    fi
}

_finish() {
    if [ -f /var/run/${0##*/}.pid ];then
        rm /var/run/${0##*/}.pid;
    fi
    exit
}

_mount() {
    /sbin/geli attach -p -k ${key_file} /dev/$device
    /bin/mkdir -p ${target} &&
    /sbin/mount /dev/${device}.eli ${target}/ &&
    /sbin/fsck_ufs -pB ${target};
}

_umount() {
    /sbin/umount /dev/${device}.eli;
    /bin/rm -r ${target};
    /bin/sync /dev/${device}.eli
    /sbin/geli detach /dev/${device};
    /bin/sync /dev/${device}
}

_sync_func() {
    /usr/local/bin/rsync -a --log-file=${origin}/backup.log ${origin}/
${target}/
    /usr/bin/logger "Finish syncing $origin on $device";
}

_start; _mount; _sync_func; _umount;
while [ -e /dev/da0 ];do echo "A8P8A8P8A8" > /dev/speaker;sleep
10;done
_finish;



Thanks in advance, >:)
-Al


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP