#!/bin/csh -f ############################################################################# # Copyright: J.Brewer/ESO 1999.############################################## ############################################################################# # # Name: disk2tape # Description: This script will write specified files to tape. # # Note: I do not put file names into a variable, else the maximum word # length (1018 characters) may be exceeded. # # # Author: James Brewer, jbrewer@eso.org # Version: 1.0, 5 May99: First release # ############################################################################# # # Check script arguments... # if($#argv < 1 || $1 == -help) then goto error endif # # Set variables... # set op = disk2tape.out # Name of log file... set bs = 28800 # Block size to use with dd command... set mt = "mt -f" # -t: SunOS, -f: HP set cnt1 = 0 # Counter for files to be written... set cnt2 = 0 # Counter for successful writes... set cnt3 = 0 # Counter for MB's written to tape... # # Define action on interrupt (^c)... # onintr cleanup # # Clear screen, initialize log... clear echo $0": Automatic Log" >! $op # # If using the -list option, check that file can be read... # if($1 == '-list' && !(-r $2)) then echo $0": Unable to read "$2 exit(-1) endif # # Set cnt1, check existence of files to be written, and calculate # the total MBs to be written.... # echo "Checking files..." if($1 == '-list') then set cnt1 = `cat $2 | wc -w` foreach file (`cat $2`) else set cnt1 = ${#argv} foreach file ($*) endif if !(-r $file) then echo $0": Unable to read "$file set reply = 0 while ($reply != 'y' && $reply != 'n') echo -n "Continue anyway? (y/n) " set reply = $< end if($reply == 'n') then exit(-1) endif else @ cnt3 = $cnt3 + (`du -s $file | cut -f1` / 2048) endif end echo " >>> Total MB of data to be written: "$cnt3" <<<" set cnt3 = 0 # # Have user select tape drive to use... # set dr = 0 while ($dr != '1' && $dr != '2' && $dr != '3' && $dr != '4') echo " " echo "Choose:" echo " 1 -- Write to DAT drive with compression" echo " 2 -- Write to DAT drive without compression" echo " 3 -- Write to DLT drive with compression" echo " 4 -- Write to DLT drive without compression" echo " " echo " (Note: use of compression is recommended)" echo " " echo -n "Enter your choice... " set dr = $< end # # Select tape drive name... # switch($dr) case 1: set dev = "/dev/rmt/0mnb" # DAT drive, no rewind with compression... breaksw case 2: set dev = "/dev/rmt/0mn" # DAT drive, no rewind... breaksw case 3: set dev = "/dev/rmt/1mnb" # DLT drive, no rewind with compression... breaksw case 4: set dev = "/dev/rmt/1mn" # DLT drive, no rewind... breaksw default: echo $0": Problem with switch statement..." exit(-1) endsw # # Check whether the drive exists on this machine... # if !(-e $dev) then echo $0": Couldn't find "$dev exit(-1) endif # # Position the tape... # echo " " set reply = 0 while ($reply != 'y' && $reply != 'n') echo -n "Is this a new tape (overwrite all data) [y/n]? " set reply = $< end if($reply == "y") then echo "Rewinding tape..." $mt $dev rew else echo "Skipping to end of data..." $mt $dev eod $mt $dev bsf 1 endif # # Write the files to tape... # if($1 == '-list') then foreach file (`cat $2`) else foreach file ($*) endif # # If file is unreadable, skip to next file... # if !(-r $file) then echo $0": Unable to read "$file", skipping to next file..." | tee -a $op continue endif # # Write the file to tape... # set start = `date "+%H:%M:%S %m/%d/%y"` echo " " | tee -a $op echo " Saving file with: dd if="$file" of="$dev "bs="$bs | tee -a $op dd if=$file of=$dev bs=$bs # # Check status to see if dd executed successfully... # if($status != 0) then echo " Problem with the dd command (maybe end of tape?)" | tee -a $op goto cleanup else @ cnt2+=1 # Increment success counter... endif # # File saved, make a summary of operations so far... # @ cnt3 = $cnt3 + (`du -s $file | cut -f1` / 2048) echo " Writing started at: "$start | tee -a $op echo " Writing finished at: "`date "+%H:%M:%S %m/%d/%y"` | tee -a $op echo " MBs written to tape: "$cnt3 | tee -a $op echo " " | tee -a $op end cleanup: echo " " | tee -a $op if ($cnt1 != $cnt2) then echo "WARNING WARNING WARNING WARNING WARNING WARNING" | tee -a $op endif echo "Wrote "$cnt2" of "$cnt1" files..." | tee -a $op echo " " echo "Choose:" echo " r -- Rewind " echo " o -- Rewind, take drive offline" echo " x -- Do nothing (default)" echo " " echo -n "Enter your choice... " set reply = $< if ($reply == 'r') then echo "Rewinding tape..." $mt $dev rew endif if ($reply == 'o') then echo "Taking tape offline..." $mt $dev offline endif exit(0) error: echo "Usage (1): "$0" file1 file2 file3" echo " where fileN is a FITS file" echo " " echo "Usage (2): "$0" -list listfile" echo " where listfile contains a listing of the names of" echo " the fits files to be saved." echo "[Further information --> "$0" -help]" echo "[See this script --> more `which "$0"`]" if($1 == "-help") then more `echo $0 | sed -e s/disk2tape/ObsLog.man/` endif exit(-1)