Auto mount/rsync/detach script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Auto mount/rsync/detach script
# 1  
Old 01-02-2011
MySQL Auto mount/rsync/detach script

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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SuSE

auto mount

Hello, We got some SUSIE servers in and we are trying to get auto mount to work. We normally mount our home directories on RHEL and Solaris to /export/home. The home directories on the Susie servers mount home directory to /home. When uses login their home directories mount. When my coworker does... (2 Replies)
Discussion started by: bitlord
2 Replies

2. Solaris

auto mount SMB share on Solaris 10

I CANNOT use autmounter so should I just write the command as an /etc/rc script or is it possible to auto mount the share via the vfstab? (4 Replies)
Discussion started by: LittleLebowski
4 Replies

3. Shell Programming and Scripting

script to auto mount remote sshfss over network

I have the folorwing three shel accounts on remote servers which i would like to auto mount at boot, bu have the auto mount be preceded by a check for an active Ethernet or 802.11 connection prito running the sshfs command. porter@tty.freeshelll.org cent1750@tty.freeshell.org... (0 Replies)
Discussion started by: FloridaBSD
0 Replies

4. UNIX for Dummies Questions & Answers

Enable and disable the auto mount

How to enable and disable the auto mount option for USB devices.? (3 Replies)
Discussion started by: ungalnanban
3 Replies

5. Solaris

NFS VS Auto Mount problem

Dear All, Struck with a peculiar problem a) /opt/a is auto mounted to /home/a for User:a When the User logs in to the server his home directory is getting mounted from the autofs i.e /home/a (/opt/a), Instead is has to mount the User home dir from NIS which is /home/a (from NIS). ... (2 Replies)
Discussion started by: saiprashant
2 Replies

6. Ubuntu

Problem to auto mount on NFS server

I am new in Ubuntu and i use Ubuntu 7.10, and have problem to mount automatic when i reboot computer, Here is my /etc/fstab 192.168.0.91:/home/DATA/it /home/USER/usertest/Documents/Z nfs defaults 0 0 I try many option in that line, but the result is same, I cannot automatic mounting the... (5 Replies)
Discussion started by: blesets
5 Replies

7. UNIX for Advanced & Expert Users

auto mount lofs

Hi All, I want to mount one directory to other. i.e /export/home/dju to /dju It's like a link ( link -s ). but I don't want to use this( link method ) . I try to use : mount -F lofs /export/home/dju /dju the question is, how do I use this mount method with automount ,... (1 Reply)
Discussion started by: mdjuarsa
1 Replies

8. UNIX for Advanced & Expert Users

CDROM Doesn't Auto Mount - Solaris 9

On Sun Fire V240, cdrom doesn't automount. I can manually mount the cdrom, however it pretty annoying. I have checked the vold demon and its seems to be running. Here is the output from /etc/inetd.conf pg inetd.conf daytime stream tcp6 nowait root internal daytime dgram udp6 ... (2 Replies)
Discussion started by: mshafi
2 Replies

9. Shell Programming and Scripting

Auto mount

Hi, I have written this Auto mount using script. xterm -e mount/filesrv xterm -e /root/parameters/param.sh& xterm -e /root/parameters/prnscript/makePRN.sh& xterm -e /root/parameters.Releasechecker.sh& After Executing this script. I am getting 6 screens. It supposed to get only 3 screens. (0 Replies)
Discussion started by: kalyani
0 Replies

10. UNIX for Dummies Questions & Answers

auto mount point

hi can i know what is the command to create auto mount point in my unix server? is there any directory which i have to go? (1 Reply)
Discussion started by: legato
1 Replies
Login or Register to Ask a Question