1#!/bin/sh 2# dumpdev.sh 1.5 08/11/87 3# shell script to dump a single device 4# the script is called with a single 5# parameter - which is the device to be dumped 6# 7# A second parameter (if set) sets the debug switch which will 8# simply print the parameters to dump and not alter any state 9PATH=:/etc:/bin:/usr/bin: 10# 11dumpdata=/etc/dumpdata 12dumpcycle=${dumpdata}/dumpcycle 13dump=/etc/dump 14labelchk="t" 15# 16dev=$1 17if [ "$1" = "" ] 18then 19 echo 'Usage: dumpdev device-name' 20 exit 1 21fi 22chkflg=no 23if [ "$2" != "" ] 24then 25 chkflg=yes 26fi 27# device can be /dev/<name> 28# so we'll look for that and split it off 29dev=`echo $dev|sed -e 's/\/dev\///'` 30# Now lets see if the device exists in the dumpcycle file 31gstr=`grep "^$dev" $dumpcycle` 2> /dev/null 32if [ "$gstr" = "" ] 33then 34# it might be a raw device 35 altdev=`expr $dev : 'r\(.*\)'` 36 if [ "$altdev" = "" ] 37 then 38 echo Sorry, cannot find device $1 in $dumpcycle 39 exit 1 40 fi 41 dev=$altdev 42 gstr=`grep "^$dev" $dumpcycle` 2> /dev/null 43 if [ "$gstr" = "" ] 44 then 45 echo Sorry, cannot find device $1 in $dumpcycle 46 exit 1 47 fi 48fi 49# Now we look for existing dump state 50# stored in a file called devicename.state on /etc/dumpdata 51statefile=${dumpdata}/${dev}.state 52if [ ! -s $statefile ] 53then 54# we ain't got one 55 STATE="0" 56else 57 STATE=`cat $statefile` 58fi 59# 60# Get the next state from the cycle file 61# 62awkprog="/^$dev/ { if ($STATE == \$2) print \$3 }" 63NEXTSTATE=`awk "$awkprog" < $dumpcycle` 64if [ "$NEXTSTATE" = "" ] 65then 66 echo "Dump state problem" 67 echo "State file $statefile contents giving current state = $STATE" 68 echo "cannot be found in $dumpcycle" 69 exit 1 70fi 71# 72# Now we need the dump information from the cycle file 73# 74awkprog="/^$dev/ { if ($NEXTSTATE == \$2) print \$4,\$5,\$6 }" 75decodethis=`awk "$awkprog" < $dumpcycle` 76if [ "$decodethis" = "" ] 77then 78 echo "Dump state problem" 79 echo "Cannot find state $NEXTSTATE in $dumpcycle" 80 exit 1 81fi 82# 83# This is really nasty - but 84# now finally set the dump level and the tape range 85echo $decodethis | ( 86 read LEVEL TAPESTEM TAPECYCLE 87 if [ "$chkflg" = yes ] 88 then 89 echo "DUMP of /dev/$dev at level ${LEVEL} to tapes $TAPESTEM $TAPECYCLE" 90 exit 1 91 fi 92 if [ "$TAPECYCLE" = "" ] 93 then 94 $dump oul${labelchk}${LEVEL} $TAPESTEM /dev/$dev 95 retval=$? 96 else 97 $dump oulm${labelchk}${LEVEL} $TAPESTEM $TAPECYCLE /dev/$dev 98 retval=$? 99 fi 100# 101# dump returns 0 on a successful dump 102# 103 if [ $retval = 0 ] 104 then 105 echo $NEXTSTATE > $statefile 106 fi 107) 108exit 0 109