LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-25-2012, 05:21 AM   #1
mm2426
LQ Newbie
 
Registered: Sep 2012
Posts: 4

Rep: Reputation: Disabled
How to take password input in a shell script in ubuntu ?


Hello friends.
I am writing a shell script which is as follows
----------------
#!/bin/bash
sudo wvdial
----------------

I named it dial and placed it on my ubuntu 11.04 desktop.
Now I invoke this script by double clicking on it.
Now I want that a input box should appear which should ask for the my password
and then should execute the script.

This script executes well when executed from the konsole.
Please Help.
 
Old 09-25-2012, 05:24 AM   #2
Neron.L
LQ Newbie
 
Registered: Sep 2012
Posts: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by mm2426 View Post
Hello friends.
I am writing a shell script which is as follows
----------------
#!/bin/bash
sudo wvdial
----------------

I named it dial and placed it on my ubuntu 11.04 desktop.
Now I invoke this script by double clicking on it.
Now I want that a input box should appear which should ask for the my password
and then should execute the script.

This script executes well when executed from the konsole.
Please Help.
Hi, I think maybe expect is what you want.
 
Old 09-25-2012, 05:34 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by Neron.L View Post
Hi, I think maybe expect is what you want.
I'm not sure about that---isn't "expect" used when one is expecting a response--eg from a website? In this case, we simply need to prompt the user for input.

I think what is needed is something like dialog or zenity. One or both should be available using the package manager.
 
Old 09-25-2012, 05:36 AM   #4
torchnw
LQ Newbie
 
Registered: Jun 2008
Distribution: Ubuntu, Debian, Mint, Fedora, Arch
Posts: 23

Rep: Reputation: 4
Use "kdesudo" or "gksudo" ( depending on your desktop environment ) instead of "sudo" for a graphical password prompt box.
 
Old 09-25-2012, 05:38 AM   #5
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 635

Rep: Reputation: 186Reputation: 186
expect is not the proper tool, I think.
As already suggested, use either kdesu or gksu to prompt a user for root password before running root-only commands.
As an alternative, you can create a .desktop file for your script which pops up a terminal window when you launch it or, otherwise, you can use some GUI controls via zenity, kdialog (part of KDE, so if you're not using it don't even bother installing all of KDE just for it) or a Unity script if you're using Unity as desktop environment.

Last edited by 414N; 09-25-2012 at 05:40 AM.
 
Old 09-25-2012, 11:24 AM   #6
mm2426
LQ Newbie
 
Registered: Sep 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks my job was done. But how to launch the terminal when I click on the shell script was not clear to me. Can you please elaborate?
 
Old 09-25-2012, 02:18 PM   #7
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,668
Blog Entries: 10

Rep: Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077Reputation: 2077
Quote:
Originally Posted by mm2426 View Post
...how to launch the terminal when I click on the shell script...Can you please elaborate?
Launcher should be...(it may vary depending on the DE you are using and terminal program for that DE, but it goes like this for gnome-terminal...
Code:
gnome-terminal -e /path/to/script.sh
Make sure it's 755 and has the shebang (#!/bin/bash or another shell) near the top of the script.

Please let us know...

Edit: the /path/to/script.sh may need quotes, ie, "/path/to/script.sh"

Last edited by Habitual; 09-25-2012 at 02:19 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using shell command output as input in shell script - how to do? EnderX Linux - Newbie 2 06-30-2010 01:46 PM
Send password input via bash script lowlifeish Linux - Software 4 02-22-2007 01:40 PM
how can I take input with a shell script? GUIPenguin Linux - General 4 04-11-2005 04:46 PM
input password & shell Rex_chaos Linux - General 1 08-01-2003 09:52 PM
script and password input Rex_chaos Linux - General 1 07-22-2003 04:04 PM


All times are GMT -5. The time now is 06:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration