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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:38:06+00:00 2026-06-17T12:38:06+00:00

I have a simple BASH script I use that sends a .esh script to

  • 0

I have a simple BASH script I use that sends a .esh script to a remote host. For example, I know what the username and password is for the host, so my script does the following:

expect login:
send root\n
expect Password:
send abc123\n
expect "# "

So, this will automatically log me into the remote host as user root with password abc123.

I am now attempting to send a BASH-style one-line for loop to pull some metrics from some log files on the host, ie:

send 'for i in /var/log/example/*.txt; do echo $i; cat $i | grep error ; done \n'

However, this fails with:

# can't read "i": no such variable
    while executing
send 'for i in /var/log/example/*.txt; do echo $i; cat $i | grep error ; done \n'

I’ve read some similar posts, but I haven’t found any case similar to this. Once I’ve figured out how to implement this, I will likely include more command-line commands to refine the output of the log files (ie: more bash temporary variables, pipe the output through awk, etc).

Can anyone help me resolve this issue?

Thank you.


EDIT: As per the provided answer, I changed my script to the following, and it worked like a charm:

expect login:
send root\n
expect Password:
send abc123\n
expect "# "
send { for i in /var/log/example/*.txt; do echo $i; cat $i | grep error ; done }
send "\n"
send exit

This logs into the remote host, prints some valuable metrics to the console, then quits telnet. I can now use a bash script on my local host to loop through multiple remote hosts via a text file containing a list of hostnames/IPs.

Thanks!

  • 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-17T12:38:07+00:00Added an answer on June 17, 2026 at 12:38 pm

    Single quotes aren’t used for quoting in Tcl, they’re normal characters. Use double quotes if you want backslash, command and variable expansion, and curly braces if you don’t.

    Replace the first ' with { and the last with }.

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

Sidebar

Related Questions

I have a fairly simple bash script that does some grep to find all
I have a bash script that I use to setup a simple php script
I have a bash script that tests whether the sftp connection exists, very simple
I am trying to write a simple bash script that will use a list
I have a simple bash script, called print_code.sh , that takes a file name,
I have a very simple script: #!/bin/bash gnuplot << EOF set term postscript portrait
I have a bash script that simply calls different calls and redirect stdout and
I have a bash script that uploads a file via SFTP, with a command
I am trying to write a simple bash script that is listening on a
Below is my shell script that is working fine. #!/bin/bash DATE_YEST_FORMAT2=`perl -e 'use POSIX

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.