iostat命令显示磁盘的详细详细脚本 用linuxshall写
时间: 2024-02-27 13:54:02 浏览: 27
以下是使用 Linux Shell 编写的 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
```
这个脚本与之前的脚本几乎相同,唯一的区别在于脚本的开头使用了 `#!/bin/bash` 声明来指定脚本应该由哪个 Shell 解释器来执行。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)