求2个shell小程序
要求:写出两个Shell程序,每个程序不少于十五行;说明程序主要功能;每行给出注释。谢谢要可以运行的请发我邮箱zhao_lan@qq.com多简单都无所谓行数够就行底楼的...
要求:写出两个Shell程序,每个程序不少于十五行;说明程序主要功能;每行给出注释。
谢谢
要可以运行的
请发我邮箱zhao_lan@qq.com
多简单都无所谓
行数够就行
底楼的貌似和我一个系的~~~~~~·· 展开
谢谢
要可以运行的
请发我邮箱zhao_lan@qq.com
多简单都无所谓
行数够就行
底楼的貌似和我一个系的~~~~~~·· 展开
3个回答
展开全部
把我以前为别人写的给你吧 不过我没有注释
说以下大致的功能
一 每隔30分钟将cpu 内存 使用的情况写入日志
#!/bin/bash
LOGPATH="."
info() {
echo "" >> $LOGPATH/log.txt
echo "" >> $LOGPATH/log.txt
echo -n "============" >> $LOGPATH/log.txt
date >> $LOGPATH/log.txt
#cpu
mpstat -A >> $LOGPATH/log.txt
echo "" >> $LOGPATH/log.txt
#memory
free -l >> $LOGPATH/log.txt
echo "" >> $LOGPATH/log.txt
#disk
df -h >> $LOGPATH/log.txt
echo "" >> $LOGPATH/log.txt
# network
# nload
}
echo "" > $LOGPATH/log.txt
while [ 2 -gt 1 ]; do
info;
sleep 1800;
done
二 做一个菜单 包夸4项功能 输入数字 选择相应的功能
第1项 显示指定的信息(如用户/shell等)
第2项 任意输入两个数,选择加减乘除 做一运算 给出结果
第3项 输入一串以0结尾的大写字字母串 给出其中最小的一个字母(按ascii码)
第4项 确认并退出
#!/bin/bash
PS3='Input option(1-4):'
stack="Display Cacluate Sort Quit"
select choice in $stack; do
if [ "$choice" = "Display" ]; then
read -p "Input you want to display[name/path/shell/cal]" info
if [ "$info" = "name" ]; then
echo "$USER"
elif [ "$info" = "path" ]; then
echo "$HOME"
elif [ "$info" = "shell" ]; then
echo "$SHELL"
elif [ "$info" = "cal" ]; then
cal 2011
fi
elif [ "$choice" = "Cacluate" ]; then
read -p "Input one number: " num1
read -p "Input the other number: " num2
read -p "Input method[A/S/M/D]: " mod
case $mod in
'A' ) echo "$num1 + $num2 is $((num1+num2))";;
'S' ) echo "$num1 - $num2 is $((num1-num2))";;
'M' ) echo "$num1 * $num2 is $((num1*num2))";;
'D' ) echo "$num1 / $num2 is $((num1/num2))";;
* ) echo "wrong method";;
esac
elif [ "$choice" = "Sort" ]; then
read -p "Input an string with 0 ended:" str
res=`echo $str | awk -F"0" '{print $1}'`
echo $res | awk -F "" '{ a=$1; for(i=2;i<NF;i++) if( $i < a) a=$i; print a}'
elif [ "$choice" = "Quit" ]; then
read -s -n1 -p "Do you really want to quit?(Y)"
if [ "$REPLY" = "Y" ];then
exit 0;
fi
else
echo "Invalid selection, Please input number."
fi
done
说以下大致的功能
一 每隔30分钟将cpu 内存 使用的情况写入日志
#!/bin/bash
LOGPATH="."
info() {
echo "" >> $LOGPATH/log.txt
echo "" >> $LOGPATH/log.txt
echo -n "============" >> $LOGPATH/log.txt
date >> $LOGPATH/log.txt
#cpu
mpstat -A >> $LOGPATH/log.txt
echo "" >> $LOGPATH/log.txt
#memory
free -l >> $LOGPATH/log.txt
echo "" >> $LOGPATH/log.txt
#disk
df -h >> $LOGPATH/log.txt
echo "" >> $LOGPATH/log.txt
# network
# nload
}
echo "" > $LOGPATH/log.txt
while [ 2 -gt 1 ]; do
info;
sleep 1800;
done
二 做一个菜单 包夸4项功能 输入数字 选择相应的功能
第1项 显示指定的信息(如用户/shell等)
第2项 任意输入两个数,选择加减乘除 做一运算 给出结果
第3项 输入一串以0结尾的大写字字母串 给出其中最小的一个字母(按ascii码)
第4项 确认并退出
#!/bin/bash
PS3='Input option(1-4):'
stack="Display Cacluate Sort Quit"
select choice in $stack; do
if [ "$choice" = "Display" ]; then
read -p "Input you want to display[name/path/shell/cal]" info
if [ "$info" = "name" ]; then
echo "$USER"
elif [ "$info" = "path" ]; then
echo "$HOME"
elif [ "$info" = "shell" ]; then
echo "$SHELL"
elif [ "$info" = "cal" ]; then
cal 2011
fi
elif [ "$choice" = "Cacluate" ]; then
read -p "Input one number: " num1
read -p "Input the other number: " num2
read -p "Input method[A/S/M/D]: " mod
case $mod in
'A' ) echo "$num1 + $num2 is $((num1+num2))";;
'S' ) echo "$num1 - $num2 is $((num1-num2))";;
'M' ) echo "$num1 * $num2 is $((num1*num2))";;
'D' ) echo "$num1 / $num2 is $((num1/num2))";;
* ) echo "wrong method";;
esac
elif [ "$choice" = "Sort" ]; then
read -p "Input an string with 0 ended:" str
res=`echo $str | awk -F"0" '{print $1}'`
echo $res | awk -F "" '{ a=$1; for(i=2;i<NF;i++) if( $i < a) a=$i; print a}'
elif [ "$choice" = "Quit" ]; then
read -s -n1 -p "Do you really want to quit?(Y)"
if [ "$REPLY" = "Y" ];then
exit 0;
fi
else
echo "Invalid selection, Please input number."
fi
done
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询