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 9053301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:23:27+00:00 2026-06-16T13:23:27+00:00

How can I instruct expect to look for something like Generating foo- [pattern] .tgz

  • 0

How can I instruct expect to look for something like “Generating foo-[pattern].tgz” in the stream and return the pattern so I can use it in future commands?

I find myself repeatedly performing the same actions and would like to automate them using expect. I ssh onto one system and run a script on it that generates a file, then I scp the file from that system onto two other systems.

I can spawn ssh and trigger the file build successfully. I’m uncertain how to capture the name of the generated file to perform the copy. The script outputs something like “Generating foo-timestamp.tgz… Done.” and timestamp obviously varies between runs, and I don’t want to glob scp (ie scp foo-*tgz) because there might be stale foo files (hence the timestamp).

I’m new to expect and still stumbling through examples and such, and occasionally still need a bit of hand holding. Any suggestions/help are much appreciated.

  • 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-16T13:23:29+00:00Added an answer on June 16, 2026 at 1:23 pm

    I am not aware if we can capture the pattern, but what I normally do in such situations is store output in a variable and then use this output. For Example, if send -- "./executeSomeScript\r" will give an output like “Generating foo-timestamp.tgz … Done”, i’ll replace the send command with

    send -- "output=`./executeSomeScript`\r"
    send -- "filename=`echo \$output | awk '{ print \$2 }'\r"
    

    and finally

    send -- "scp \$filename user@server:path\r"
    

    Please note that escaping $ is necessary so that it is not interpreted at script level but send as literal to the remote shell.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can use SELECT * FROM table WHERE id IN (478,278,190,890,123) to return a
Can anyone instruct me on the proper way to use the MySQLi extension in
is there a string in regular expressions that can instruct it to autoincrement it's
How can I instruct my Swing component to grab focus right now ? requestFocus()
Can someone instruct me how to save the state of the checkbox's of a
Is there a way that I can instruct WCF to accept JSON that is
How can I instruct the system to reload all kernel modules that have changed?
I'm having a problem. How can I instruct my XSLT to insert a new
I have an object in a worker thread, which I can instruct to stop
How can I instruct python to store, internally, a pre-hashed version of my strings,

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.