Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1122467
  • 博文数量: 150
  • 博客积分: 2739
  • 博客等级: 少校
  • 技术积分: 2392
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-07 12:28
文章分类

全部博文(150)

文章存档

2015年(2)

2014年(16)

2013年(10)

2012年(58)

2011年(64)

分类: Python/Ruby

2011-09-27 15:13:55

获取内存信息的脚步:
#!/bin/bash
#
USAGEINFO() {
  # $1 is the free space
  local ISPERCENT=$[$1*100/$2]
  if [ $ISPERCENT -lt 10 ]; then 
    echo -e "\033[31;1mWarning:\033[0m the free space is too less ."
  else
    echo -e "\033[32;1mThe free space is ${ISPERCENT}%.\033[0m"
  fi
}

MEMINFO() {
  TOTAL=`awk '/^'"${1}Total"'/{print $2}' /proc/meminfo` 
  FREE=`awk '/^'"${1}Free"'/{print $2}' /proc/meminfo` 
  local USED=$[$TOTAL-$FREE]
  echo "-------------------------------------------"
  echo -e " \033[1m${1}Total      ${1}Free      ${1}Used\033[0m"
  echo "-------------------------------------------"
  echo " ${TOTAL}kb       ${FREE}kb     ${USED}kb"
  echo "-------------------------------------------"
  USAGEINFO $FREE $TOTAL
}

cat << EOF
1) Display the Memory information.
2) Display the Swap information.
EOF

read -p "Your choice: " SWITCH

case $SWITCH in
'1')
   MEMINFO Mem
  ;;
'2')
  MEMINFO Swap
  ;;
*)
  echo "Wrong choice, the correct options is '1' and '2'."
  exit 1
  ;;
esac
增加用户的脚步:
#!/bin/bash
# This about useradd user and delete user

for I in {1..20};do
  useradd linux$I 
  echo "linux$I" | passwd --stdin linux$I
done
tail -20 /etc/passwd | awk -F: '{ print "ROOT" $1 ",UID" $3 ",GID" $4}'
   
#for I in {1..20};do 
#  userdel -r linux$I 
#done

#tail -5 /etc/passwd
登陆小脚步:
#!/bin/bash
#
#read user
w | cut -d: -f1 | grep 'nnnnnnn'
A=$?

  if [ $A -eq 0 ];then
      echo "redhat is logged on."
     else
       echo "the pc mast sleep"
        sleep 5
   fi

阅读(863) | 评论(0) | 转发(0) |
0

上一篇:贪吃蛇

下一篇:脚步--设置ip信息

给主人留下些什么吧!~~