Want to create a GUI to query user for username and password and mount using sshfs. Here is the BASH script which does this:
===
echo "input username:"
read username
sshfs $username@<ip address>:/home/$username /home/tux/Documents
===
Can someone point me in the right direction.

Howto Write Simple User Input GUI
(16 posts) (5 voices)-
Posted 13 years ago #
-
Use zenity?
Posted 13 years ago # -
zenity, yad, xdialog, dialog (not real GUI, pretty much console-emulated pseudo-GUI), gtkdialog, Tcl/Tk... much of them are packaged for SliTaz.
Posted 13 years ago # -
Stay with shell programming. Use xdialog. It's very simple and powerful. If you go with zenity the learning curve is much longer. With zenity you need to know the basic language. Not so with xdialog or similar ones that goes very handy with the shell. If you know some shell programming, expant on it.
Try it. You will see what I mean immediately.Posted 13 years ago # -
I would recommend yad over xdialog or gtkdialog.
Posted 13 years ago # -
Huu ? zenity and yad are even simplier than Xdialog. dialog is then console ancestor of Xdialog.
There is NO language for zenity and yad, same as Xdialog, you may have been confused by these ones.
gtkdialog is the only one to be more complicated.local username=$(zenity --entry --text="Username"); echo "username = $username"
local username=$(yad --entry --text="Username"); echo "username = $username"
Can it be more simple ? (probably lol, but it is already *very* simple ;-} )Regards,
--BabaorumPosted 13 years ago # -
I like how easy yad is and how many of the options are assumed like pressing the return key equals the OK or yes button and closing the window equals the cancel or no button. It's small thing like that, that's useful. Most of the new boxes used in cooking use yad as it's base now.
Posted 13 years ago # -
Good suggestions all and I looked at yad and zenity. Somebody's also posted some code on usernames and password inputs. Slitaz, however, is throwing an error not recognizing 2inputsbox.
Now I am not a programmer, so please bear with me here:
a. Able to get a username and password done in Xdialog - written to variables
b. Can pass the username to the next command, sshfs $USERNAME@blah blah blah
c. How is the password given at the "Password:" prompt?Posted 13 years ago # -
Trixar, I like yad also. I have it running and can do the script described above. I just cannot find any documentation on how to use it to pass passwords for login.
Posted 13 years ago # -
I see this post at http://library.gnome.org/users/zenity/stable/zenity-text-entry-options.html.en
#!/bin/sh
if zenity --entry \
--title="Add an Entry" \
--text="Enter your _password:" \
--entry-text "password" \
--hide-text
then echo $?
else echo "No password entered"
fiSo, we can capture the password, but how to pass it on?
Posted 13 years ago # -
Did you read my answer Sidhu ? I've given an example just for you, answers are put into variables.
You may read the output of built-in help:yad --help
, all is very clear there.Do it sequentially, it is best because you just have to wait the GUI to display, type the answer and press ENTER. No need at all to press TAB to go to the next answer field.
local username=$(yad --entry --text="Username") local pword=$(yad --entry --text="Password" --hide-text) sshfs $username $pword [etc.] #or whatever the sshfs command wants you to enter
Type this in a shell script, inserting "#!/bin/sh" at the very first line, alone, get it executable and you are done.
Posted 13 years ago # -
The example you gave tests if you entered a password and then echos it back to you. It does this by using echo $? - $? being the captured password. You could probably use $@ too.
Not that it matters. Both should work. The trick is to use --hide-text to hide text entry. Learning a bit of bash scripting and syntax help too ;)
Posted 13 years ago # -
Thanks Babaorum!
This is what I have and it works!
#!/bin/sh
local username=$(yad --entry --text="Username")
local pword=$(yad --entry --text="Password" --hide-text)
echo "$pword"|sshfs -o password_stdin $username@192.168.100.20:/home/$username /home/tux/Documentsa. I realized the use of "-o password_stdin"
b. Although the above script works, I want to do both username and password input in one screen, not twoSo, stay tuned...
Posted 13 years ago # -
So, this is one screen with username and password inputs. And password input is hidden. Obviously you can further generalize the script by making the IP address a variable and asking for it in a third user input.
#!/bin/sh
frmdata=$(yad --title "Mount file server" --form --field="username" --field="Password:H")
frmusername=$(echo $frmdata | awk 'BEGIN {FS="|" } { print $1 }')
frmpassword=$(echo $frmdata | awk 'BEGIN {FS="|" } { print $2 }')
echo "$frmpassword"|sshfs -o password_stdin $frmusername@192.168.100.20:/home/$frmusername /home/tux/DocumentsPosted 13 years ago # -
Posted 13 years ago #
Reply »
You must log in to post.