具有Zenity的Bash登录脚本用于CIFS挂载

Y

我正在编写Windows共享的安装脚本,以便在登录后运行。我已经用bash和zenity做到了,它可以工作,但是现在我需要做得更好,因此,如果用户名字段和密码字段为空,则返回到输入。

例子

    wUsername=`zenity --entry --width=300 --title="Mount $MOUNTDIR" --text="Kasutajanimi:"`
#if [ $? -ne 0 ]; then
#       exit 1
#fi
if [ -z "$wUsername" ]; then
        zenity --error --title="Viga kasutajanimes!" --text="Palun sisestage oma kasutajanimi"


# get the windows password
wPassword=`zenity --entry --width=300 --title="Mount $MOUNTDIR" --text="Parool:" --hide-text`
if [ $? -ne 0 ]; then
        exit 1
fi

因此,如果Kasutajanimi aka用户名或Parool aka密码为空,我希望此脚本将用户拉回输入即使按下空格。

我已经在所有功能强大的Google上进行了搜索,并且知道以某种方式可以退货。

芒登

我会这样:

#!/usr/bin/env bash

## Define a function that launches the zenity username dialog
get_username(){
    zenity --entry --width=300 --title="Mount $MOUNTDIR" --text="Kasutajanimi:" 
}
## Define a function that launches the zenity password dialog
get_password(){
    zenity --entry --width=300 --title="Mount $MOUNTDIR" --text="Parool:" --hide-text
}

## Attempt to get the username and exit if cancel was pressed.
wUsername=$(get_username) || exit

## If the username is empty or matches only whitespace.
## See http://www.tldp.org/LDP/abs/html/string-manipulation.html
## for an explanation of this syntax. The . means any non-space
## character so when this is less than 1, the username is empty
## or just whitespace. Since this is a while loop, the process
## will be repeated until the username is correctly submitted.
while [ "$(expr match "$wUsername" '.')" -lt "1" ]; do
    zenity --error --title="Viga kasutajanimes!" --text="Palun sisestage oma kasutajanimi"
    wUsername=$(get_username) || exit
done

## Same as the previous loop but for the password. Sorry if
## the message is wrong, I don't speak this language :)
wPassword=$(get_password) || exit

while [ "$(expr match "$wPassword" '.')" -lt "1" ]; do
    zenity --error --title="Viga Parool!" --text="Palun sisestage oma Parool"
    wPassword=$(get_password) || exit
done

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

bash脚本-带有if语句的Zenity列表

来自分类Dev

用于登录网站的BASH脚本

来自分类Dev

具有用于执行bash脚本的入口点的Dockerfile

来自分类Dev

Bash脚本,用于杀死具有特定名称的进程

来自分类Dev

systemd挂载周期,用于cifs挂载的bind挂载

来自分类Dev

具有OR条件的Bash脚本

来自分类Dev

无法使用smbclient登录到samba共享,但通过cifs挂载

来自分类Dev

Bash脚本,用于写入具有5个以上文件的子目录

来自分类Dev

Bash脚本if语句具有多个条件

来自分类Dev

具有grep命令理解的bash脚本

来自分类Dev

具有后台进程的bash脚本

来自分类Dev

具有多行和Grep的Bash脚本

来自分类Dev

Bash脚本if语句具有多个条件

来自分类Dev

具有Qt UI的Bash脚本程序

来自分类Dev

使用 fstab 挂载带有 cifs 的网络驱动器

来自分类Dev

内部具有较小脚本的Bash脚本

来自分类Dev

Cifs挂载问题

来自分类Dev

CIFS 自动挂载适用于 ubuntu 12 但不适用于 ubuntu 16

来自分类Dev

Zenity bash命令不适用于Java

来自分类Dev

用于复制具有所需名称的文件的脚本

来自分类Dev

用于递归创建具有内容的新文件的脚本

来自分类Dev

带有用于备份目录的 bash 脚本的奇怪输出

来自分类Dev

运行位于CIFS挂载中的脚本时,出现Segfault和/或“致命错误:未知:无法打开...”

来自分类Dev

登录后运行bash脚本

来自分类Dev

Bash脚本禁用root登录

来自分类Dev

bash脚本登录到网页

来自分类Dev

Bash 登录脚本奇怪的行为

来自分类Dev

具有bash脚本的重复性任务

来自分类Dev

Bash脚本-检查具有花括号的字符串