devops 信创在数字经济时代提升企业竞争力的关键策略
545
2022-09-25
收集的脚本
#======================================================
#!/bin/sh
VIF="eth1"
VIF_S=0
VIF_E=15
for ((VIF_S=$VIF_S;$VIF_S - $VIF_E;VIF_S++))
do
vconfig add $VIF $VIF_S
done
#=========================拨号用的============================
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
. /etc/rc.d/rc.status
modprobe ppp_generic
modprobe pppoe
case "$1" in
start)
echo -n "* Starting pppoe: "
pppd plugin rp-pppoe.so eth0 mtu 1412 noipdefault noauth default-asyncma
p \
defaultroute hide-password nodetach usepeerdns mtu 1492 mru 1492 noaccomp \
nodeflate nopcomp novj novjccomp user CD87059820 lcp-echo-interval 20 \
lcp-echo-failure 3 >/dev/null 2>&1 &
# logger -t WAN "PPPoE Connection is offline, Attempting re-connect!">/dev
/null
check_status
;;
stop)
echo -n "* Stopping pppoe: "
killall pppd >/dev/null 2>&1 &
check_status
;;
restart)
sleep 5
$0 stop
$0 start
;;
check)
PPPID=`pidof pppd`
if [ -z $PPPID ];then
echo "pppoe is disconnected at `date|awk '{print $3"/"$2 " - " $4}'`">>/
var/log/pppoe.log
$0 start
else
false
fi
;;
*)
#======================================================
check_status()
{
PREV_ERR=$?
echo -en "\\033[75G"
if [ $PREV_ERR = 0 ]; then
# echo -en "\\033[1;34m"
echo -en "[ ok ]"
else
# echo -en "\\033[1;31m"
echo -en "[ !! ]"
fi
echo -e "\\033[0;39m"
unset PREV_ERR
}
#======================================================
一道shell编程题拿来做练习,初学awk,写的乱七八糟,但还算是做出来了:)
原题连接
TITLE=title
export AUTHOR=author
export CATEGORY=category
export STATUS=in
export BNAME=none
export DATE=`date +%Y/%m/%d`
#add a book
add_mode(){
clear
read -p "UNIX library ----ADD MODE
Title: " TITLE
read -p "Author: " AUTHOR
read -p "Category: " CATEGORY
echo "$TITLE:$AUTHOR:$CATEGORY:$STATUS:$BNAME:$DATE" >> library
read -p "Any more to add? Yes or No >" YORN
if [ $YORN = "y" -o $YORN = "Y" ]; then
add_mode
else
lib_mng
fi
}
#delete a book
del_mode(){
clear
read -p "delete: " DELNAME
awk -v DEL="$DELNAME" 'BEGIN{FS=":"}{if(DEL==$1) print "UNIX library ----DELETE MODE\n" \
"Title:",$1"\n" "Author:",$2"\n" "Category:",$3"\n" "Status:",$4"\n" "Checked out by:",$5"\n" "Date:",$6}' library
read -p "Delete this book? Yes or No >" YON1
if [ $YON1 = "Y" -o $YON1 = "y" ];then
sed -i '/^'$DELNAME'/d' library
read -p "Any more to del? Yes or No >" YON2
if [ $YON2 = "Y" -o $YON2 = "y" ];then
del_mode
else
lib_mng
fi
else
lib_mng
fi
}
#display a book
display_mode(){
clear
DISINFO="can not find this book"
read -p "display: " DISNAME
for i in $(awk 'BEGIN{FS=":"} {print $1}' library)
do
if [ $i = $DISNAME ];then
DISINFO=`awk -v DIS="$DISNAME" 'BEGIN{FS=":"}{if(DIS==$1) print "UNIX library ----Display MODE\n" \
"Title:",$1"\n" "Author:",$2"\n" "Category:",$3"\n" "Status:",$4"\n" "Checked out by:",$5"\n" "Date:",$6}' library`
#DISINFO="haha"
#break
fi
done
echo $DISINFO
read -p "Any more to look for?Yes or No>" YON3
if [ $YON3 = "Y" -o $YON3 = "y" ];then
display_mode
else
lib_mng
fi
}
#update a book's status
update_mode(){
clear
read -p "title: " UPNAME
awk -v UP="$UPNAME" 'BEGIN{FS=":"}{if(UP==$1) print "UNIX library ----UPDATE MODE\n" \
"Title:",$1"\n" "Author:",$2"\n" "Category:",$3"\n" "Status:",$4"\n" "Checked out by:",$5"\n" "Date:",$6}' library
STATUS=`awk -v UP="$UPNAME" 'BEGIN{FS=":"}{if(UP==$1) print $4}' library`
if [ $STATUS = "in" ];then
read -p "studentname is: " BNAME
DATE=`date +%Y/%m/%d`
awk -v UP="$UPNAME" 'BEGIN{FS=OFS=":"}{if(UP==$1) {$4="out";$5="'$BNAME'";$6="'$DATE'"};print >"library"}' library
echo "New status: out"
else
DATE=`date +%Y/%m/%d`
awk -v UP="$UPNAME" 'BEGIN{FS=OFS=":"}{if(UP==$1) {$4="in";$5="none";$6="'$DATE'"};print >"library"}' library
echo "New status: in"
fi
read -p "Any more to update?Yes or No>" YON4
if [ $YON4 = "Y" -o $YON4 = "y" ];then
update_mode
else
lib_mng
fi
}
#report library's status
report_mode(){
clear
awk 'BEGIN{FS=":"}{print "UNIX library ----DELETE MODE\n" "Title:",$1"\n" "Author:",$2"\n" \
"Category:",$3"\n" "Status:",$4"\n" "Checked out by:",$5"\n" "Date:",$6}' library | more
lib_mng
}
#master mode
lib_mng(){
clear
read -p "UNIX library manager
0.exit this program
1.add a book
2.delete a book
3.display a book
4.update a book's status
5.report library's status
Input your choice: " NUM
case $NUM in
"0")
exit 1
;;
"1")
add_mode
;;
"2")
del_mode
;;
"3")
display_mode
;;
"4")
update_mode
;;
"5")
report_mode
;;
*)
echo "Invalid chioce,press any key to try again"
;;
esac
}
lib_mng
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~