#!/bin/csh -f # "@(#) $Id: disk2tape,v 1.32 2002/01/29 05:36:56 vltsccm Exp $" ############################################################################# # 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: # 2.0, 10 Jul00: ohainaut, changes for NTT # 1.1, 12 Apr00: Switch on uname for mt flag added # 1.0, 05 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 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... # # Determine Unix flavor, and set mt flag accordingly... # switch (`uname`) case HP-UX: echo "Setting parameters for HP-UX..." set mt = "mt -t" breaksw case SunOS: echo "Setting parameters for SunOS..." set mt = "mt -f" breaksw case Linux: echo "Setting parameters for Linux..." set mt = "mt -f" breaksw default: echo $0": Unrecognized system architecture..." exit(-1) endsw # # 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') then if (!(-r $2)) then echo $0": Unable to read "$2 exit(-1) endif 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 endif if (-r $file) then @ 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... # #ntt# set dr = 0 #ntt#while ($dr != '1' && $dr != '2' && $dr != '3' && $dr != '4') #ntt# echo " " #ntt# echo "Choose:" #ntt# echo " 1 -- Write to DAT drive with compression" #ntt# echo " 2 -- Write to DAT drive without compression" #ntt# echo " 3 -- Write to DLT drive with compression" #ntt# echo " 4 -- Write to DLT drive without compression" #ntt# echo " " #ntt# echo " (Note: use of compression is recommended)" #ntt# echo " " #ntt# echo -n "Enter your choice... " #ntt# set dr = $< #ntt#end # # Select tape drive name... # #ntt: set dr = 1 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)