linux命令练习:磁盘管理相关练习
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux命令练习:磁盘管理相关练习相关的知识,希望对你有一定的参考价值。
练习一
1、写一个脚本
1)显示一个菜单给用户
d|D) show disk usages.
m|M) show memory usages.
s|S) show swap usages.
*) quit.
2) 当用户给定选项后显示相应的内容:
扩展:
当用户选择完成,显示相应信息后,不退出;而让用户再一次选择,再次
显示相应的内容;除了用户使用quit.
#!/bin/bash
#program:
#练习磁盘管理相关脚本编写
#history donggen 2016-11-03-10:19
PATH=http://www.11.qixoo.com/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bash
export PATH
cat << EOF
d|D) show disk usages.
m|M) show memory usages.
s|S) show swap usages.
*) quit.
EOF
read -p "Your choice:" CHOICE
while [ $CHOICE != "quit" ]; do
case $CHOICE in
d|D)
df -Ph ;;
m|M)
free -m ;;
s|S)
free -m | grep ‘Swap‘ ;;
*)
echo "Unknown.." ;;
esac
read -p "Again,Your choice:" CHOICE
done
[ test]# ./showsystem.sh
d|D) show disk usages.
m|M) show memory usages.
s|S) show swap usages.
*) quit.
Your choice:d
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 4.9G 1.5G 3.1G 33% /
tmpfs 947M 0 947M 0% /dev/shm
/dev/sda1 2.0G 61M 1.8G 4% /boot
/dev/sda3 3.9G 73M 3.6G 2% /home
/dev/sda7 2.0G 35M 1.8G 2% /tmp
/dev/sda5 2.9G 1.7G 1.2G 59% /usr
Again,Your choice:D
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 4.9G 1.5G 3.1G 33% /
tmpfs 947M 0 947M 0% /dev/shm
/dev/sda1 2.0G 61M 1.8G 4% /boot
/dev/sda3 3.9G 73M 3.6G 2% /home
/dev/sda7 2.0G 35M 1.8G 2% /tmp
/dev/sda5 2.9G 1.7G 1.2G 59% /usr
Again,Your choice:S
Swap: 1999 0 1999
Again,Your choice:N
Unknown..
Again,Your choice:M
total used free shared buffers cached
Mem: 1893 181 1711 0 42 62
-/+ buffers/cache: 76 1816
Swap: 1999 0 1999
Again,Your choice:quit
[ test]#
以上是关于linux命令练习:磁盘管理相关练习的主要内容,如果未能解决你的问题,请参考以下文章