1 Reply Latest reply on Dec 10, 2012 9:41 AM by Dude!

    script error - sed

      Hi ,
      while i am executing the below command it is working fine.

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

      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.


      Edited by: Ani on Dec 10, 2012 1:05 PM
        • 1. Re: script error - sed
          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:

          $ echo "teststring" > testfile
          $ a=teststring
          $ sed -i 's\$a\##INC000010580362\g' testfile; cat testfile
          $ sed -i "s\\$a\##INC000010580362\g" testfile; cat testfile
          "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.