Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
cat > z.sh <<EOT
#!/bin/bash
if [ -n "$4" ]; then
  LOG="$4"
else
  LOG="/var/tmp/zfstest.\$(date +%F-%T).txt"
fi
ipa=\$(sudo ifconfig | grep -A 1 vmxnet3s0 | sed '1d; s/^[ \\t]*inet[ \\t]*//; s/[ \\t]*netmask.*\$//')
sudo /sbin/zpool destroy testpool
sudo -E /usr/sbin/svcadm disable -s svc:/system/fmd:default
sudo -E find /var/fm/fmd -type f -exec rm {} \\;
sudo -E /usr/sbin/svcadm enable svc:/system/fmd:default
# we need 3 x 8G drives with 512b sector size
export DISKS="\$1 \$2 \$3"
export KEEP="rpool data"
export ZFS_USE_ONLY_DISKS=yes
#remove partition on disks
for D in \$DISKS
do
    sudo -E /usr/bin/dd if=/dev/null of=/dev/dsk/\${D}p0 bs=512 count=512K
done
# cleanup drives before tests:
sudo -E /sbin/zpool create -f test123321 \$DISKS
sudo -E /sbin/zpool destroy test123321
sudo -E rm -rf /tmp/mnt* /tmp/ufs.* /tmp/log.* /tmp/tmp.* /tmp/rst* /tmp/tmpfs*
test -d /var/tmp/test_results && sudo rm -rf /var/tmp/test_results
sudo -E /usr/sbin/devfsadm -C
uname -a > \${LOG}
echo "IP Address : \${ipa}" >> \${LOG}
echo "" >> \${LOG}
echo "Disk IDs : \$DISKS" 2>&1 | /usr/bin/tee -a \${LOG}
# run tests
/bin/ksh /opt/zfs-tests/bin/zfstest \$* 2>&1 | /usr/bin/tee -a /var/tmp/z.tmp
echo "Results Summary" >> \${LOG}
echo "" >> \${LOG}
skip=\$(sed -n '/^SKIP[ \\t]*/p' /var/tmp/z.tmp | sed 's/^SKIP[ \\t]*//; s/[ \\t]*\$//')
fail=\$(sed -n '/^FAIL[ \\t]*/p' /var/tmp/z.tmp | sed 's/^FAIL[ \\t]*//; s/[ \\t]*\$//')
pass=\$(sed -n '/^PASS[ \\t]*/p' /var/tmp/z.tmp | sed 's/^PASS[ \\t]*//; s/[ \\t]*\$//')
total=0
if [ "\${pass}" != "" ]; then
    total=\$((\${total} + \${pass}))
fi
if [ "\${fail}" != "" ]; then
    total=\$((\${total} + \${fail}))
fi
if [ "\${skip}" != "" ]; then
    total=\$((\${total} + \${skip}))
fi
echo "TOTAL TESTS:     \$total" >> \${LOG}
sed '1,/Results Summary/d' /var/tmp/z.tmp >> \${LOG}
sudo rm -f /var/tmp/z.tmp
EOT
chmod 777 z.sh

...

Then you can disconnect in any time by pressing Ctrl-A d and connect back in the new SSH session by the command:

...

Code Block
languagebash
cat > stab_zfs.sh <<EOT
#!/bin/bash
get_duration() {
  IFS=':' read -r -a tm <<< "\$1"
  num=\${#tm[@]}
  delta=\$((\${tm[0]} * 3600))
  if [[ \$num -gt 1 ]]; then
    delta1=\$((\${tm[1]} * 60))
    (( delta += \$delta1 ))
    if [[ \$num -gt 2 ]]; then
      (( delta += \${tm[2]} ))
    fi
  fi
  echo \$delta
}
get_time_diff() {
  local cur_time=\$(date +%s)
  echo \$((\$cur_time - \$1))
}
print_time_diff() {
  local delta=\$(get_time_diff \$1)
  local sec=\$((\$delta % 60))
  let "amin = \$delta / 60"
  let "hour = \$amin / 60"
  local min=\$((\$amin%60))
  if [ -n "\$2" ]; then
    printf " Running time: %02d:%02d:%02d\\n" \$hour \$min \$sec >> \$2
  else
    printf " Running time: %02d:%02d:%02d\\n" \$hour \$min \$sec
  fi
}
log_extra() {
  echo "---------------- ZPOOL LIST ------------------" >> \$1
  zpool list >> \$1
  echo "----------------  ZFS LIST  ------------------" >> \$1
  zfs list >> \$1
  echo "----------------    PS AX   ------------------" >> \$1
  ps ax >> \$1
  echo "---------------- TOP  -n 10 ------------------" >> \$1
  top -n 10 >> \$1
}
i=1
mode=0
TOTALLOG="/var/tmp/stabzfs.\$(date +%F-%T).txt"
dsk1=\$1
shift
dsk2=\$1
shift
dsk3=\$1
shift
echo "============ ZFS Stability test started at \$(date +%F-%T) ==============" > \${TOTALLOG}
if [[ \$# < 2 ]]; then
  echo "Missing parameters in the command" | /usr/bin/tee -a \${TOTALLOG}
  exit 1
fi
case "\$1" in
  -i) mode=1
      # number of iterations is provided
      maxiter=\$2
      echo "Stability Test : launched for \$maxiter iterations at \$(date)." | /usr/bin/tee -a \${TOTALLOG}
      ;;
  -d) mode=2
      # duration of tests is provided
      delta=\$(get_duration \$2)
      echo "Stability Test : launched for \$2 interval (\$delta seconds) at \$(date)." | /usr/bin/tee -a \${TOTALLOG}
      ;;
  -t) mode=3
      # stop date/time is provided
      stopdt=\$2
      ;;
  *)  echo "Stability Test : \$1 is a wrong option" | /usr/bin/tee -a \${TOTALLOG}
      echo "Usage : stab_zfs.sh <disk1> <disk2> <disk3> (-i <iterations> | -t <HH:MM[:SS]> | -d <HH:MM[:SS] [DAY-MONTH-YEAR]>]) [-s | <test name>]"
      exit 1
      ;;
esac
shift
shift
if [[ \$mode -eq 3 ]]; then
  # stop time/date mode
  if [[ \$# > 0 ]]; then
    date -d \$1 +%s
    stopat=\$?
    if [[ \$stopat -eq 0 ]]; then
      # stop date is entered after the time
      # if it is ommited then date is treated as current one
      stopdt="\$stopdt \$1"
      shift
    fi
  fi
  echo "Stability Test : launched until \$stopdt at \$(date)." | /usr/bin/tee -a \${TOTALLOG}
  stopat=\$(date -d "\$stopdt" "+%s")
fi
uname -a | /usr/bin/tee -a \${TOTALLOG}
diskinfo >>>  /dev/null
diskinfo >>> /dev/null
echo "---------------- DISKINFO -----------------------" >> \${TOTALLOG}
diskinfo | /usr/bin/tee -a \${TOTALLOG}
GLOB_START_TIME=\$(date +%s)
while [[ \$mode -gt 0 ]]
do
  case "\$mode" in
  1) # number of iterations is provided
     if [[ \$i -gt \$maxiter ]]; then
       break
     fi
     ;;
  2) # duration of tests is provided
     difftm=\$(get_time_diff \$GLOB_START_TIME)
     if [[ \$difftm -gt \$delta ]]; then
       break
     fi
     ;;
  3) # stop date/time is provided
     tmpat=\$(date +%s)
     if [[ \$stopat -le \$tmpat ]]; then
       break
     fi
     ;;
  *) break
     ;;
  esac
  LOG="/var/tmp/zfstest.\$(date +%F-%T).txt"
  echo "----------------------- Pass \${i} <\${LOG}>: started \$(date)" | /usr/bin/tee -a \${TOTALLOG}
  echo "---------------- BEADM LIST -----------------------" >> \${TOTALLOG}
  beadm list | /usr/bin/tee -a \${TOTALLOG}
  echo "---------------- ZPOOL LIST -----------------------" >> \${TOTALLOG}
  zpool list | /usr/bin/tee -a \${TOTALLOG}
  START_TIME=\$(date +%s)
  ./z.sh \$dsk1 \$dsk2 \$dsk3 \$LOG
  print_time_diff \${START_TIME} \${TOTALLOG}
  echo "----------------------- Pass \${i} : finished \$(date)" | /usr/bin/tee -a \${TOTALLOG}
  (( i++ ))
done
echo "Tests are finished successfully at \$(date) with \${i} passes." >> \${TOTALLOG}
print_time_diff \${GLOB_START_TIME} | /usr/bin/tee -a \${TOTALLOG}
EOT
sed -i '/./!d' stab_zfs.sh && chmod 777 stab_zfs.sh

...