注意:若直接復(fù)制的的話腳本內(nèi)容格式會(huì)非常亂解決方法
1.Esc
2.光標(biāo)到開頭Ctrl+v
3.上下鍵選中所有
4.按=即可恢復(fù)正確格式
注:腳本內(nèi)容cat追加部分:cat與最后一個(gè)EOF需頂格,自行手動(dòng)修改注:此腳本邏輯有部分地方有bug佣蓉,下一篇文章更完善
#!/bin/bash
sum=30 #初始余額總數(shù)
msg=15 #發(fā)一條短信需要15分
menu () {
cat << EOF
當(dāng)前余額為$sum 分,每條短信需要$msg 分
==========================
1.充值
2.發(fā)消息
3.退出
==========================
EOF
}
recharge () {
read -p "請(qǐng)輸入充值金額:" money
expr $money + 1 &>/dev/null
if [ $? -eq 0 ]
then
((sum=$sum+$money))
echo "充值成功梁丘,剩余余額為:$sum"
main
else
ec
echo "請(qǐng)輸入要充值的正確的金額(正整數(shù))浩淘!"
recharge
fi
}
ec () {
echo " "
}
note () {
read -p "輸入要發(fā)送的內(nèi)容:" note
((sum=$sum-$msg))
echo "發(fā)送成功爷怀,余額剩余:$sum"
}
yno () {
read -p "請(qǐng)問是否繼續(xù)發(fā)送(yes/no):" yno
ec
if [ "$yno" == "yes" ]
then
note
elif [ "$yno" == "no" ]
then
exit 0
else
echo "請(qǐng)輸入(yes或者no)"
yno
fi
}
panduan () {
read -p "是否充值(yes/no):" yn
ec
if [ "$yn" == "yes" ]
then
recharge
elif [ "$yn" == "no" ]
then
exit 0
else
echo "請(qǐng)輸入(yes或者no)"
panduan
fi
}
news () {
if [ $sum -lt 15 ]
then
echo "余額不足$msg徐鹤,請(qǐng)充值"
panduan
else
while true
do
if [ $sum -lt 15 ]
then
echo "余額不足$msg,如想發(fā)送短信請(qǐng)充值"
panduan
else
ec
read -p "輸入要發(fā)送的內(nèi)容:" note
((sum=$sum-$msg))
echo "發(fā)送成功糟袁,余額剩余:$sum"
ec
yno
if [ $sum -lt $msg ]
then
ec
echo "余額不足辜窑,剩余$sum分"
panduan
fi
fi
done
fi
}
main () {
while true
do
menu
ec
read -p "請(qǐng)選擇要做的操作:" a
sleep 1
clear
case $a in
1)
recharge
;;
2)
news
;;
3)
exit 0
;;
*)
echo "輸入錯(cuò)誤,請(qǐng)輸入正確的選項(xiàng)"
esac
done
}
main
實(shí)現(xiàn)信息發(fā)送發(fā)郵件下面
#!/bin/bash
sum=30 #初始余額總數(shù)
msg=15 #發(fā)一條短信需要15分
mails=`cat /etc/mail.rc |wc -l`
menu () {
cat << EOF
當(dāng)前余額為$sum 分,每條短信需要$msg 分
==========================
1.充值
2.發(fā)消息
3.退出
==========================
EOF
}
recharge () {
read -p "請(qǐng)輸入充值金額:" money
expr $money + 1 &>/dev/null
if [ $? -eq 0 ];then
((sum=$sum+$money))
echo "充值成功,剩余余額為:$sum"
main
else
ec
echo "請(qǐng)輸入要充值的正確的金額(正整數(shù))吊趾!"
recharge
fi
}
ec () {
echo " "
}
mail () {
if [ $mails -lt 70 ];then
cat >>/etc/mail.rc<< EOF
set from=xxxxxxx@163.com smtp=smtp.163.com smtp-auth-user=xxxxxxx smtp-auth-password=xxxxxxxxxxxxxx smtp-auth=login
EOF
else
:
fi
}
note () {
mail
read -p "輸入要發(fā)送的內(nèi)容:" note
((sum=$sum-$msg))
echo $note >/tmp/youjian.txt
mailx -s "短信" xxxxxxxxxx_idc@126.com </tmp/youjian.txt
echo "發(fā)送成功咙鞍,余額剩余:$sum"
}
yno () {
read -p "請(qǐng)問是否繼續(xù)發(fā)送(yes/no):" yno
ec
if [ "$yno" == "yes" ];then
note
elif [ "$yno" == "no" ];then
exit 0
else
echo "請(qǐng)輸入(yes或者no)"
yno
fi
}
panduan () {
read -p "是否充值(yes/no):" yn
ec
if [ "$yn" == "yes" ];then
recharge
elif [ "$yn" == "no" ];then
exit 0
else
echo "請(qǐng)輸入(yes或者no)"
panduan
fi
}
news () {
if [ $sum -lt 15 ];then
echo "余額不足$msg,請(qǐng)充值"
panduan
else
while true
do
if [ $sum -lt 15 ];then
echo "余額不足$msg趾徽,如想發(fā)送短信請(qǐng)充值"
panduan
else
ec
note
ec
yno
if [ $sum -lt $msg ];then
ec
echo "余額不足续滋,剩余$sum分"
panduan
fi
fi
done
fi
}
main () {
while true
do
menu
ec
read -p "請(qǐng)選擇要做的操作:" a
sleep 1
clear
case $a in
1)
recharge
;;
2)
news
;;
3)
exit 0
;;
*)
echo "輸入錯(cuò)誤,請(qǐng)輸入正確的選項(xiàng)"
esac
done
}
main