iostat命令显示磁盘的详细详细脚本
时间: 2024-02-27 17:55:35 浏览: 75
这是一个 iostat 命令的详细脚本,用于显示磁盘的详细信息:
```bash
#!/bin/bash
# iostat disk usage script
# Set the disk name
DISK=sda
# Set the time interval in seconds
INTERVAL=5
# Set the number of iterations
ITERATIONS=10
# Print header
echo "Disk Usage - iostat"
echo "---------------------"
# Loop through the iterations
for ((i=0; i<$ITERATIONS; i++))
do
# Get the disk usage statistics
DISK_STATS=$(iostat -d -k $DISK $INTERVAL 1 | tail -n 1)
# Parse the statistics
DISK_UTIL=$(echo $DISK_STATS | awk '{print $util}')
DISK_READ=$(echo $DISK_STATS | awk '{print $read}')
DISK_WRITE=$(echo $DISK_STATS | awk '{print $write}')
# Print the statistics
echo "Utilization: $DISK_UTIL%"
echo "Reads/sec: $DISK_READ"
echo "Writes/sec: $DISK_WRITE"
echo "---------------------"
# Sleep for the interval
sleep $INTERVAL
done
```
在脚本中,您可以设置磁盘名称、时间间隔和迭代次数。脚本将使用 iostat 命令获取磁盘使用统计信息,并在每次迭代中打印磁盘利用率、每秒读取和写入的次数。
阅读全文