- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Prompting a user for a password within a scrip...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2007 02:52 AM
тАО09-10-2007 02:52 AM
I am writing a script that will provide a telnet connection to a remote server. What I need to do is have the user prompted for his/her password during the execution of the script.
I checked the system in question for expect, and it is not installed. I could go through the motions of installing it, but before I do, I would like to see if read would work in this scenario. The shell that I am using is bash, and the OS is Fedora Core 2. What syntax would I use for read in order to have the user prompted for a username and password once the telnet session is initiated? Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2007 03:29 AM
тАО09-10-2007 03:29 AM
SolutionBut this if you need authenticate the user to run the script, is not related to the remote password.
Now, if you want to prompt for the remote password, then you do need expect or something similar, anyway, telnet is something that you should stop using and you should use SSH instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2007 05:01 AM
тАО09-10-2007 05:01 AM
Re: Prompting a user for a password within a script
Thanks for your reply. Using SSH is not an option because the server in question does not have it installed at this time. Eventually it will, but until then, telnet is the only available method of terminal connectivity.
I've included the text of the script in this reply. The user does not need a sudo account to execute the script, the username and password prompt will occur when the telnet session is initiated. The syntax within the script I need is how to have the user prompted for the username and password. The script should pause until this information is entered, and then proceed accordingly. Thanks.
#!/bin/bash
# This script will provide access to the tcs # application which is located on the
# mcrs1 server.
# First disable access control so that clients can connect from any host.
xhost +
# Establish a telnet session with mcrs1. NOTE: The address in question is
# the address that mcrs1 has on the Partners network, and not the internal
# tcs network address. The syntax shown below is designed to prompt the
# operator for the appropriate username and password.
telnet
# Configure the display environmental variable on mcrs1 so that X applications
# can run on the workstation that has made the connection to mcrs1 setenv DISPLAY
# Execute the tcs application so that it appears on the workstation.
# Change to the directory where the executable is located, and then run it.
# NOTE: Do NOT include the '&' symbol at the end of the executable. The
# terminal window needs to be running in the background in order for TPR
# to work properly.
cd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2007 07:21 AM
тАО09-10-2007 07:21 AM
Re: Prompting a user for a password within a script
regards,
ivan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-10-2007 07:39 PM
тАО09-10-2007 07:39 PM
Re: Prompting a user for a password within a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-11-2007 12:57 AM
тАО09-11-2007 12:57 AM
Re: Prompting a user for a password within a script
#!/usr/bin/perl
use strict;
my $pass=(getpwuid($<))[1]; # the $pass variable will hold the crypted password of the user executed this script
my $again=0;
my $passwd;
do {
if ($again == 1 ) {
print "Sorry! Wrong password. Try again.\n";
}
print "Please enter your password:\n";
system "stty -echo";
$passwd=
chomp $passwd;
$again=1;
system "stty echo";
} while (crypt($passwd,$pass) ne $pass);
print "You've got it!\n";