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

  • Home
  • SEARCH
  • 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 7610315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:23:21+00:00 2026-05-31T01:23:21+00:00

I am writing a simple expect script for accessing to a remote server without

  • 0

I am writing a simple expect script for accessing to a remote server without introducing the password with the command window.

I am able to access to the remote server, and there I want to modify a text file. This modification is performed with the ‘sed‘ command for finding a ‘keyword’, the line where this ‘keyword’ is located is deleted.

The part of the code that is giving me problems is the combination of ‘spawn‘ with ‘sed‘ is the following one

spawn sed -i -e '/keyword_to_delete/d' /home/my_file

Since this is doing in a expec file I have to do it through ‘spawn’ command. I switch on the debug info mode and the main error info in the screen is :

expect: set expect_out(buffer) "exit\r\nsed: -e expression #1, char 1: unknown command: `''\r\n"
cannot interact with self - set spawn_id to a spawned process

I hope I have show the problem here clear and in a nice way, if not tell me and I will try to do it better.

Thanks so much

CODE:

 set ip [lindex $argv 0]

 set port [lindex $argv 1]

 set password <PSWD>


proc sendPass {} {

global ip
global port
global password

spawn "/usr/bin/ssh" -X -p $port root\@$ip "-o StrictHostKeyChecking no" "-o UserKnownHostsFile /dev/null"

while {1} {
  expect {
    "IN"                     {break}
    "Are you sure you want"     {send "yes\r"}
    "assword"                   {send "$password\r"}
  }
}

spawn chmod 775 /etc/hosts
spawn sed -i -e {/operator/d} /etc/hosts
spawn sed -i -e {/default/d} /etc/hosts

send "exit\r"
expect eof

}; # end proc sendPass

#execute proc
sendPass


# script itself terminates
interact

And the current error is : “sed: couldn’t open temporary file /etc//sedDEb2Fx: Permission denied”

  • 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-05-31T01:23:22+00:00Added an answer on May 31, 2026 at 1:23 am
    1. Again I’m not an expert of expect, but your script looks to swawn chmod and sed on your local machine, not on your remote machine. Shouldn’t you use send chmod 775 ... instead, just like you’re using send exit to execute exit on your remote machine?

    2. This is how sed -i ... works. You will notice that you need a write permission on /etc where a temp file will be created. To avoid it you need to explicitly create a temp file by not using -i, eg. sed -e /foo/d /etc/hosts > /tmp/hosts; mv /tmp/hosts /etc. Maybe you need cp instead of mv, but I’m not sure… I’m too lazy to try strace mv ... by myself.

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

Sidebar

Related Questions

I'm planning on writing a simple text viewer, which I'd expect to be able
I am writing a simple database with web access. I have previous experience with
I'm currently writing a simple .sh script to parse an Exim log file for
I'm writing simple chat program in Ada, and I'm having problem with chat window
I'm writing a server that I expect to be run by many different people,
I'm writing simple program to communicate between smart devices and I receive 11001 when
I'm looking into writing simple graphics code in Android and I've noticed some synchronized()
I am writing simple site that requires users and profiles to be handled. The
How long does it take for an experienced Windows programmer to learn writing simple
I'm writing a simple OpenGL application that uses GLUT . I don't want 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.