跳板机脚本

闲来无事,弄了个跳板机脚本

#!/bin/sh
#fencatn
i=1
trapper(){
trap ':' INT EXIT TSTP TERM HUP #把常规的退出都屏蔽掉
}
main(){
while [ $i -le 3 ]
do
trapper
clear
let i++
cat<<menu
1)service1-test-192.168.31.145
2)mysql-test-192.168.31.147
3)没看懂上面写什么吧,给你翻译下:输入1或者输入2
4)最多试3次,再来就输入go命令
menu
echo '翻译:喊你输个数字,1或者2,注意,有彩蛋,你猜猜~'
read -p"Pls input a num.:" num
case $num in
1)
echo 'login in service1~192.168.31.145.'
echo '我们准备跳了,给你3秒思考人生,坐好扶稳~'
sleep 3
ssh [email protected]
;;
2)
echo 'login in mysql~192.168.31.147.'
echo '我们要跳了啊,给你5秒系安全带,坐好扶稳~'
sleep 5
ssh [email protected]
;;
110)
echo "your birthday:"
read -p "不错,猜对了,但是还没完,想想我们什么发工资,几号:" char
if [ "$char" = "10"];then
echo "猜对了,程序即将毁灭,虚拟机即将销毁,倒计时3秒开始"
exit
sleep 3
fi
;;
*)
echo "select error."
echo "输错了,哥子"
sleep 3
esac
done
}
main

写成个脚本,写到.bashrc就行了。我是以普通用户,放在/usr/bin/程序名,然后.bashrc添加这个程序名就行了

[[email protected] ~]$ ll /usr/bin/go
-rwxr-xr-x 1 root root 1359 Jul 3 11:29 /usr/bin/go
[[email protected] ~]$ tail -1 .bashrc 
go
[[email protected] ~]$ tail .bashrc 
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions
go
[[email protected] ~]$

别忘了给脚本+x权限

此条目发表在LinuxBasic分类目录,贴了标签。将固定链接加入收藏夹。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注