Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-09-2021, 01:56 PM
BjoernH BjoernH is offline
Registered User
 
Join Date: Mar 2018
Posts: 53
Need help using 'read -s' to prompt for password from menuitem

Good day.

I'm trying to write a menuitem which will prompt the user for a password before ssh to a server.

Here's what I tried but it won't pause to prompt for the password input:

Code:
POPUPMENU "&ConfD CLI"
  MENUITEM "&ssh nacmadmin@admin-td", "SEND", "read -s $'Enter nacmadmin password:  ' pw\n;ssh -q nacmadmin@`kgetpo|grep ^cli-|awk '{print $6}'`\n\p${pw}\n"
  END
END
Please advise.

Regards,
Bjoern
Reply With Quote
  #2  
Old 03-09-2021, 03:14 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,096
Quote:
Originally Posted by BjoernH View Post
but it won't pause to prompt for the password input
MENUITEM "&ssh nacmadmin@admin-td", "SEND", "read -s $'Enter nacmadmin password: ' pw\n;ssh -q nacmadmin@`kgetpo|grep ^cli-|awk '{print $6}'`\n\p${pw}\n"
When manually typing {Enter} in SecureCRT's terminal window, a Carriage Return (\r) is usually sent, not a Newline (\n).

If you need to simulate pressing the {Enter} key on the keyboard as part of a SEND_STRING operation, you should use \r, not \n.

If you change all of your \n to \r, do you get better behavior?

If you still experience problems, would you be so kind as to provide a complete description of the behavior you experience when attempting to use this command?

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #3  
Old 03-09-2021, 03:34 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,096
Even after you fix the SEND_STRING operation to use Carriage Returns instead of Newlines, you'll still be running into problems because everything is working exactly as you've configured it!

You've told SecureCRT to send this:
read -s $'Enter nacmadmin password: ' pw\r;ssh -q nacmadmin@`kgetpo|grep ^cli-|awk '{print $6}'`\r\p${pw}\r
...which means that the following command is launched by the shell you sent it to...
read -s $'Enter nacmadmin password: ' pw
... which summarily engages in reading input -- input which you've already sent as part of your SEND_STRING operation. What ends up getting stored in your 'pw' variable is this...
;ssh -q nacmadmin@`kgetpo|grep ^cli-|awk '{print $6}'`
If you desire to have there be a pause between your 'read' command and the subsequent 'ssh' command, you'll need to add enough \p sequences to equal the maximum time you're willing to allow the end user to type in their password. For example, to pause for 30 seconds to allow for password entry:
read -s $'Enter nacmadmin password: ' pw\r\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p\p;ssh -q nacmadmin@`kgetpo|grep ^cli-|awk '{print $6}'`\r\p${pw}\r
Just be aware that this isn't ideal because either the end user will always have to wait some number of seconds after typing in their password or they'll not enter the password in quickly enough and the ssh command will launch too quickly.

What you really need is for some way to have SecureCRT prompt you for input, and then use that input later on in the command, and that's something that the SEND_STRING functionality doesn't yet support.

I've added a feature request on your behalf for a feature that would help achieve your goal in this regard. Although the product director may evaluate it for potential inclusion in some future release, I don't yet have any ETA for when or even if this might ever become available. However, if something along these lines becomes available, we will be happy to post here with news of it.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 10:56 PM.