码迷,mamicode.com
首页 > 系统相关 > 详细

linux命令练习:磁盘管理相关练习

时间:2016-11-03 19:24:37      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:read case while

     练习一

  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=/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

[root@xuelinux 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     

[root@xuelinux test]# 



本文出自 “学linux历程” 博客,请务必保留此出处http://woyaoxuelinux.blog.51cto.com/5663865/1868930

linux命令练习:磁盘管理相关练习

标签:read case while

原文地址:http://woyaoxuelinux.blog.51cto.com/5663865/1868930

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!