linux多选项菜单脚本,linux shell 编写菜单脚本事例
menu2文件代码:
---
#!/bin/sh
#menu2
#Main menu script
#ignore ctrl-c and QUIT interrupts
trap "" 2 3 15
MYDATE=`date +%d/%m/%Y`
THIS_HOST=`hostname -s`
USER=`whoami`
#user level file
USER_LEVELS=priv.user
#hold file
HOLD1=hold1.$$
#colour function
function colour ()
{
case $1 in
black_green)
echo '[40;32m'
;;
black_yellow)
echo '[40;33m'
;;
black_white)
echo '[40;37'
;;
black_cyan)
echo '[40;36m'
;;
red_yellow)
echo '[41;33m'
;;
esac
}
#just read a single key please
function get_char()
{
#get_char
#save current stty setting
SAVEDSTTY=`stty -g`
stty cbreak
dd if=/dev/tty bs=1 count=1 2>/dev/null
stty -cbreak
#restore stty
stty $SAVEDSTTY
}
#turn the cursor on or off
function cursor ()
{
#turn cursor on/off
_OPT=$1
case $_OPT in
on ) echo '[?25h'
;;
off) echo '[?25l'
;;
*) return 1
;;
esac
}
#check what privilege level the user has
function restrict ()
{
colour red_yellow
echo -e -n "\n\n\007 Sorry your are not authorised to use this function"
colour black_green
}
function user_level ()
{
#read in the priv.user file
while read LINE
do
case $LINE in
#ignore comments
\#*) ;;
*) echo $LINE>>$HOLD1
;;
esac
done < $USER_LEVELS
FOUND=false
while read MENU_USER PRIV
do
if [ "$MENU_USER" = "$USER" ] ; then
FOUND=true
case $PRIV in
yes|YES)
return 0
;;
no|NO)
return 1
;;
esac
else
#no match found read next record
continue
fi
done
if [ "$FOUND" = "false" ] ; then
echo "Sorry $USER you have not been authorsied to use this menu"
exit 1
fi
}
#called when user selects quit
function my_exit ()
{
colour black_white
cursor on
rm *.$$
exit 0
}
tput init
#display their user levels on the screen
if user_level ; then
ACCESS="Access Mode is High"
else
ACCESS="Access Mode is Normal"
fi
tput init
while :
do
tput clear
colour black_green
cat <
$ACCESS
---------------------------------------------------------------------
User:$USER Host:$THIS_HOST Date:$MYDATE
---------------------------------------------------------------------
1:ADD A RECORD
2:VIEW A RECORD
3:PAGE ALL RECORD
4:CHANGE A RECORD
5:DELETE A RECORD
P:PRINT ALL RECORDS
H:Help screen
Q:Exit Menu
---------------------------------------------------------------------
MAYDAY
colour black_cyan
echo -e -n "\tYour Choice [1,2,3,4,5,P,H,Q] >"
CHOICE=`get_char`
case $CHOICE in
1) ls
;;
2) vi
;;
3) who
;;
4) if user_level; then
ls -l | wc
else
restrict
fi
;;
5) if user_level;then
sort /etc/passwd
else
restrict
fi
;;
P|p) echo -e "\n\nPrinting recirds ......"
;;
H|h)
tput clear
cat <
This is the help screen ,nothing here yet to help you!
MAYDAY
;;
Q|q) my_exit
;;
*) echo -e "\t\007unknown user respense"
;;
esac
echo -e -n "\tHit the return key to continue"
read DUMMY
done
---
priv.user 文件代码:
#root quanxian wei YES, daia quanxianwei no
root yes
daia no
-----------------------------------
脚本执行后界面如下图:
linux多选项菜单脚本,linux shell 编写菜单脚本事例相关推荐
- Linux安装Flash脚本,Linux(CentOS)下的Shockwave Flash shell一键更新脚本
原创内容,转载请注明出处: https://www.myzhenai.com.cn/post/2318.html https://www.myzhenai.com/thread-17933-1-1.h ...
- 学习 shell —— 编写基本脚本
set:查看环境变量: 0. 简单说明 一般而言,shell 会通过 PATH 变量来查找命令,如果要执行用户编写的脚本(未添加进 PATH 路径),还需两步操作: 需要 $ ./xx 为需执行该脚本 ...
- Photoshop脚本 使用ExtendScript编写Ps脚本
源自:http://coolketang.com/tutorials/menu1lesson3.php 本节课程将演示如何使用ExtendScript编写脚本,它是由Adobe公司开发的一款脚本语言工 ...
- linux多级菜单脚本教程,linux shell 编写菜单脚本事例
menu2文件代码: --- #!/bin/sh #menu2 #Main menu script #ignore ctrl-c and QUIT interrupts trap "&quo ...
- linux shell 编写菜单脚本事例
menu2文件代码: --- #!/bin/sh #menu2 #Main menu script #ignore ctrl-c and QUIT interrupts trap "&quo ...
- linux 编写系统服务,Linux shell编写系统服务脚本
事先准备工作:源码安装apache .安装目录为/usr/local/httpd 任务需求: 1.可通过 service httpd start|stop|status|restart 命令对服务进行 ...
- linux shell写服务,Linux shell编写系统服务脚本
事先准备工作:源码安装apache .安装目录为/usr/local/httpd 任务需求: 1.可通过 service httpd start|stop|status|restart 命令对服务进行 ...
- linux python cpu温度,linux-raspbian系统下编写python脚本显示树莓派的当前cpu温度、使用率、内存和硬盘信息...
描述:之前查看树莓派的温度一直都需要输命令: cd /sys/class/thermal/thermal_zone0 然后cat temp 才能给出数据比如45084,给出的数据需要除以1000才是实 ...
- bashsupport插件_如何用 bash-support 插件将 Vim 编辑器打造成编写 Bash 脚本的 IDE
IDE(集成开发环境)就是这样一个软件,它为了最大化程序员生产效率,提供了很多编程所需的设施和组件. IDE 将所有开发工作集中到一个程序中,使得程序员可以编写.修改.编译.部署以及调试程序. 在这篇 ...
最新文章
- 基于PAM认证方式详解
- 自动升级失败,缺少System.resources.dll?
- PHP 设计模式之策略模式
- 对几个submission文件迅速做voting操作
- 用python处理excel表格_如何用python处理excel数据 | 用python处理excel表格数据类型
- oneproxy mysql_在OneProxy的基础上实行MySQL读写分离与负载均衡
- 还在浪费时间创建工程图?6分钟教你自定义SOLIDWORKS工程图模板
- Mac M1系统安装pytorch
- 不是所有的战略规划都可以用BLM
- 基础乐理--增长音值的补充记号
- 支付宝H5,微信H5,微信公众号支付回调
- C语言编译器和amd兼容吗,Intel的“霸道”:深究编译器对CPU性能的影响
- BZOJ——T 1707: [Usaco2007 Nov]tanning分配防晒霜
- PSINS源码阅读—test_SINS_trj
- 华为OD机试-优先级打印机
- 如何用python绘制圆_python怎么画圆
- 从网易云音乐说起,看如何打造优质的评论区
- 连续两个南航的研究生面试出了从来没出现过的问题,本科和研究生都是计算机专业的,竟然说static是不可更改的。
- 80年来最强龙卷风袭击古巴首都 致4死195伤
- mysql 查找课程最高分,查询每门课程的最高分
热门文章
- 基于java TCP实现网络通信聊天室《建议收藏附完整源码》
- 2014 java面试题_2014 java面试题 (答案)
- 万年历c语言大作业实验,用C语言写的一个万年历
- php任务分配思路_PHP执行定时任务的几种方法思路
- 多相机坐标转换_使用KITTI数据集实现坐标转换
- 希尔排序--Java
- C++ 查看输入流中的下一个字符
- php sslv3握手失败,Boost Beast握手:sslv3警报握手失败错误
- 两用物项许可证办理流程_一指通 | 出口许可证办理流程
- C/C++混淆点-左移右移操作符