Announcement

Collapse
No announcement yet.

Remote SSH command not working with sed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Remote SSH command not working with sed

    I can run the following command on the remote server

    sed -i '/address/c\address 11.11.11.11' /myfile
    to replace any line having address with address 11.11.11.11 in /myfile

    But, from my local system, this command is not working

    ssh [email protected] sed -i '/address/c\address 11.11.11.11' /myfile
    I'm getting the following error message

    Code:
    sed: can't read 11.11.11.11: No such file or directory
    How to fix this problem?

  • #2
    To replace you can use sed in the following way:

    sed -i 's/^.*address/address 11.11.11.11/' myfile
    This regex have to find "address" in your file and replace it for "address 11.11.11.11".

    Comment


    • #3
      You are averting the expansion on the local shell, but you have to conserve everything till the command to run, sed in this case, on both shells.

      Quote the sed command to run:
      ssh [email protected] "sed -i '/address/c\address 11.11.11.11' /myfile"
      Mostly, any quoting method over the current would do as well, however using double quotes like above would be simpler and cleaner.

      Comment


      • #4


        I am running an application on a remote server which outputs a link to a webpage. It actually runs a program and passes the link as a parameter.

        I use SSH to connect to the server and run this application. I would like to be able to automatically open this link on my local machine using a Tutuapp 9Apps Showbox browser.
        Last edited by winkibili; 03-04-21, 10:33 AM.

        Comment

        Working...
        X