This discussion is archived
1 Reply Latest reply: Dec 10, 2012 1:41 AM by Dude! RSS

script error - sed

Ani Newbie
Currently Being Moderated
Hi ,
while i am executing the below command it is working fine.

[root@xxxxxx5vv05]# sed -i '$a\##INC000010580362' /etc/fstab
[root@xxxxxx5vv05]

But while running from "expect script " it is showing error

++++++++++++++++++++++++++++++++++++++++++++++++
[root@xxxxx5vv05 ~]# can't read "a": no such variable
while executing
"send "sed -i '$a\##INC000010580362' /etc/fstab\r""
invoked from within
"expect "#*" {send "sed -i '$a\##INC000010580362' /etc/fstab\r"}"
("foreach" body line 12)
invoked from within
"foreach ip $ip_list {

if { $ip != ""} {
spawn ssh -oStrictHostKeyChecking=no cog1234@$ip

expect "assword*" {send "xxxxxx\r"}

expect "$*" {send ..."
(file "./df-check.expect" line 8)
[root@xxxxx5vv05 ~]#

Can someone help me.

Regards,
Ani

Edited by: Ani on Dec 10, 2012 1:05 PM
  • 1. Re: script error - sed
    Dude! Guru
    Currently Being Moderated
    Can you please put your script between code tags as described in the forum FAQ?
    sed -i '$a\##INC000010580362' /etc/fstab
    What is this command supposed to do? What are you trying to accomplish?

    Single quotes (') surrounding a string normally prevent variable expansion. You may have to escape the $ sign using a slash (\) and double quotes ("). For instance:

    {code}
    $ echo "teststring" > testfile
    $ a=teststring
    $ sed -i 's\$a\##INC000010580362\g' testfile; cat testfile
    teststring
    $ sed -i "s\\$a\##INC000010580362\g" testfile; cat testfile
    ##INC000010580362
    {code}
    "send "sed -i '$a\##INC000010580362' /etc/fstab\r""
    To run a sed command from within an expect script, one normally uses the "spawn" command. Btw, sed -i will edit files in place and not return anything.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points