xref: /aosp_15_r20/external/sg3_utils/scripts/scsi_stop (revision 44704f698541f6367e81f991ef8bb54ccbf3fc18)
1#!/bin/bash
2
3################################################
4#
5#  Spin down the given SCS disk(s).
6#
7#  SCSI disks (or disks that understand SCSI commands)
8#  are assumed. By default, the immediate bit is set so the
9#  command should return immediately. The disk however will
10#  take 10 seconds or more to spin down. The '-w' option
11#  causes each stop to wait until the disk reports that it
12#  has stopped.
13#
14#  This script assumes the sg3_utils package is installed.
15#
16###############################################
17
18verbose=""
19immediate="-i"
20
21usage()
22{
23  echo "Usage: scsi_stop [-h] [-v] [-w] <device>+"
24  echo "  where:"
25  echo "    -h, --help           print usage message"
26  echo "    -v, --verbose        more verbose output"
27  echo "    -w, --wait           wait for each stop to complete"
28  echo ""
29  echo "Send SCSI START STOP UNIT command to stop each <device>"
30}
31
32opt="$1"
33while test ! -z "$opt" -a -z "${opt##-*}"; do
34  opt=${opt#-}
35  case "$opt" in
36    h|-help) usage ; exit 0 ;;
37    v|-verbose) verbose="-v" ;;
38    w|-wait) immediate="" ;;
39    *) echo "Unknown option: -$opt " ; exit 1 ;;
40  esac
41  shift
42  opt="$1"
43done
44
45if [ $# -lt 1 ]
46  then
47    usage
48    exit 1
49fi
50
51for i
52do
53# Use '-r' (read-only) otherwise using a block device node
54# (e.g. 'sg_start 0 /dev/sdb') can result in a change of state
55# event causing the disk to spin up again immediately.
56        echo "sg_start -r $immediate 0 $verbose $i"
57        sg_start -r $immediate 0 $verbose $i
58done
59