#! /bin/tcsh -f # # must NOT have anyone logged in on the console! # # 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 # echo "no mountable drives found." sleep 10 continue endif echo "found mountables: $mountables" set userdir = `reset_runs.com -dryrun | awk '/^dry run:/{print $NF}'` echo "current userdir: $userdir" 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 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 echo "failed to mount $sdx with rw,uid=${userid},gid=831,umask=0000,flush" mount -v -o rw,uid=${userid},gid=831,umask=0000 $sdx $mountpoint endif if( $status ) then echo "failed to mount $sdx with rw,uid=${userid},gid=831,umask=0000 " mount.exfat -o rw,uid=${userid},gid=831,umask=0000,flush $sdx $mountpoint endif if( $status ) then echo "failed to mount $sdx as exfat with rw,uid=${userid},gid=831,umask=0000,flush " mount -v -o rw,umask=0000,flush $sdx $mountpoint endif if( $status ) then echo "failed to mount $sdx with rw,umask=0000,flush " mount -v -o rw,flush $sdx $mountpoint endif if( $status ) then echo "failed to mount $sdx with rw,flush " mount -v -o rw $sdx $mountpoint endif if( $status ) then echo "failed to mount $sdx with rw " echo "out of options, drive failed to mount" endif echo "done with mount attempts for $sdx" mkdir -p ${mountpoint}/${datedir} chown -R ${username}.831 ${mountpoint}/${datedir} find ${mountpoint}/ -type d -exec chmod a+rwx \{\} \; df ${mountpoint} end set mounted = 1 set was_mounted = 0 while ( $mounted ) sleep 10 set mounted = `df $mountpoint | grep $sdx | wc -l` if( $mounted ) set was_mounted = 1 # echo "mounted = $mounted" end if($was_mounted) sleep 300 end end exit