获取内存信息的脚步:
#!/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
阅读(974) | 评论(0) | 转发(0) |