Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8416025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:37:19+00:00 2026-06-10T01:37:19+00:00

Using OSX I’d like to access $(pbpaste) within Expect. So for example this alias

  • 0

Using OSX I’d like to access $(pbpaste) within Expect.

So for example this alias connects to a copied ip address (assuming I copied it before executing it)- leaving me to enter the password:

alias s='ssh $(pbpaste) -l root'

And this script connects me to the specific host listed in the script entering the password for me:

#!/usr/bin/expect
spawn  ssh hostname -l username
expect "password:"
send "secret\n"
interact

I would like to incorporate the $(pbpaste) into the expect script so that the copied host is accessed and the password is entered for me too. How?

On a side note, I’m aware of ssh keys, and thats its generally poor form to put passwords in plain text. In my situation this is unimportant and won’t help me – the utility of getting the above EXPECT script working with $(pbpaste) variable as the hostname is more important to me.

Additionally, I would like to be able to pass the host as an argument instead of $(pbpaste) too. This is secondary to the original question though- one script for each? Or a default of $(pbpaste) if no argument for host is provided? Which ever is easier to write/ understand.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:37:21+00:00Added an answer on June 10, 2026 at 1:37 am

    I can’t test it, but this should work:

    spawn ssh [exec pbpaste] -l username
    

    Or with a command line argument:

    #!/usr/bin/expect
    if {$argc == 0} {
      set hostname [exec pbpaste]
    } else {
      set hostname [lindex $argv 0]
    }
    spawn ssh $hostname -l username
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, For all of this I am using Mac OSX Snow Leopard. I have
I'm using Mac OSX Lion and I would like to have a script that
I am trying to list all alias files in Mac Osx using the Qt.
I'm using OSX snow leopard, for the record. When I use emacs straight from
I'm currently using the OSX app LiveReload v2.1. It watches and compiles my HAML
I want to distribute my app on OSX (using py2app) and as a Debian
I am using MonoDevelop 2.8.8.4 and MonoFramework (MDK) 2.10.9_8. I'm also using Mac OSX
I understand that using postgres on osx is a little difficult because it has
I'm on OSX Lion using wkhtmtopdf that came with homebrew (0.9.9) and all of
I'm on OSX Lion using TextMate to write my C++ programs. I wanted to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.