#! /bin/tcsh -f # # must NOT have anyone logged in on the console! # Currently this works on crush17 # James's script for automatically mounting removable drives, # Creates directories, opens a terminal on graphics3, and starts backups! # It starts the backup when a RUN1 dataset has been defined AFTER the script # has started # set path = ( $path /programs/beamline/ ) while ( 1 ) # look for big partitions that are not mounted cat /etc/mtab /proc/partitions |\ awk '/^\/dev\/sd/{n=split($1,w,"/");sdx1=w[n];\ ++mounted[sdx1];\ sdx=sdx1;gsub("[1-9]$","",sdx);\ ++mounted[sdx];}\ $4~/^sd/ && $3+0>60000{sdx1=$4;\ sdx=sdx1;gsub("[1-9]$","",sdx);\ if(! mounted[sdx] && sdx!=sdx1) print "/dev/"$4}' |\ cat >! /tmp/mountables.txt set mountables = `cat /tmp/mountables.txt` rm -f /tmp/mountables.txt if("$mountables" == "") then sleep 1 continue endif echo "found mountables: $mountables" set userdir = `reset_runs.com -dryrun | awk '/^dry run:/{print $NF}'` set username = `echo $userdir | awk -F "/" '{print $3}'` set userid = `grep "^${username}:" /etc/passwd | awk -F ":" '{print $3}'` set subdir = `echo $userdir | awk -F "/" '{print $(NF-1)}'` set datedir = `echo $userdir | awk -F "/" '{print $NF}'` set userrootdir = `dirname $userdir` if(! -d "$userrootdir") then mkdir -p $userdir chown -R ${username}.831 $userrootdir endif if("$userid" == "") then echo "ERROR: what happend to $username ? " set username = "mcfuser" set userid = 15487 endif touch this set datasetfiles = 0 while ( ! $datasetfiles ) set datasetfiles = `find ${userrootdir} -name '*_1_*.cbf' -cnewer this | wc -l` if(! $datasetfiles) sleep 30 end rm this set datasetfile = `find ${userrootdir} -name '*_1_*.cbf' -cnewer this | awk '{print $1;exit}'` set datedir = `echo $datasetfile | awk -F "/" '{print $4}'` set otherdirs = `ls -l ${userrootdir} | egrep "^d" | grep -v $datedir | wc -l` if( $otherdirs ) then set userdir = ${userrootdir}/${datedir} else set userdir = ${userrootdir} endif set n = 0 foreach sdx ( $mountables ) @ n = ( $n + 1 ) if($#mountables == 1) set n = "" set mountpoint = /media/${subdir}${n}/ mkdir -p $mountpoint chmod a+rwx $mountpoint chown ${userid}.831 $mountpoint chown ${userid}.831 $sdx chmod a+rwx $mountpoint chmod a+rwx $sdx set test = `df $sdx | tail -n 1 | awk '{print ( $NF != "/dev" )}'` if($test) then umount $sdx endif set test = `df $sdx | tail -n 1 | awk '{print ( $NF != "/dev" )}'` if($test) then umount -f $sdx endif set test = `df $sdx | tail -n 1 | awk '{print ( $NF != "/dev" )}'` if($test) then umount -lf $sdx endif echo "mounting $sdx on $mountpoint" mount -v -o rw,uid=${userid},gid=831,umask=0000,flush $sdx $mountpoint if( $status ) then mount -v -o rw,uid=${userid},gid=831,umask=0000 $sdx $mountpoint if( $status ) then mount.exfat -o rw,uid=${userid},gid=831,umask=0000,flush $sdx $mountpoint if( $status ) then mount.exfat -o rw,uid=${userid},gid=831,umask=0000 $sdx $mountpoint if( $status ) echo "Sorry, drive failed to mount" endif endif endif mkdir -p ${mountpoint}/${datedir} chown -R ${username}.831 ${mountpoint}/${datedir} su - ${username} -c 'ssh graphics3 "setenv DISPLAY :0.0 ; xhost +"' su - ${username} -c 'setenv DISPLAY graphics3:0.0 ; gnome-terminal -t "data backup of '${userdir}' to usb disk '${mountpoint}/${datedir}'" -e "rsync_usb.com '${userdir}' '${mountpoint}/${datedir}' "' end end exit su - ${userid} -c 'setenv DISPLAY dataserver2:0.0 ; gnome-terminal -t "data backup to usb" --geometry 160x20+0+0 -e "rsync_usb.com '${userdir}' '/media/${subdir}${n}/${datedir}'/"' -e "rsync_usb.com ${userdir} /media/${subdir}${n}/${datedir}/" gnome-terminal -t "data backup to usb" --geometry 160x20+0+0 \ -e "rsync_usb.com ${userdir} /media/${subdir}${n}/${datedir}/" end end mount -o rw,users $sdx /media/${subdir}${n}/ mount -o uhelper=udisks $sdx /media/${subdir}${n}/ mount -o rw,uid=${userid},gid=831,umask=0777,flush $sdx /media/${subdir}${n}/ rw,nosuid,nodev,uhelper=udisks,uid=15487,gid=831,shortname=mixed,dmask=0077,utf8=1,flush