Edit file line on remote machine
Hi,
after few days of trying i have decided to ask for help. My problem is following, i am writing script for editing specific line in specific file on remote machine using ssh. Problem is i cant pass double quotes in my variable. To be clear, here is the command i use to edit file: -before script comes to this line i have exported variable called $w- sshpass -p 'PASSWORD' ssh root@IP_ADDRESS -o StrictHostKeyChecking=no 'sed -i '12s/.*/few_words="'$w'"/' /path/to/file Now, everything works fine but i can not get double quotes in remote file. Result should be few_words="variable", what i get is few_words=variable. When i execute this command locally it works ( i get few_words="variable"), but in script it does not. Thanks in advance... |
A few things to try:
1) Escape the double-quote: Code:
sed -i '12s/.*/few_words=\"'$w'\"/' /path/to/file 3) Add an extra line substituting "few_words=variable" few_words="variable" |
[QUOTE=pingu;4792516]A few things to try:
1) Escape the double-quote: Code:
sed -i '12s/.*/few_words=\"'$w'\"/' /path/to/file 2) Put the command in a file on remote machine, make it executable and call that file via ssh. yes, this is solution (i have tried it works), but i can't believe it is not possible to send double-quotes in variable via ssh? i mean extra script just for double-quotes??? Thank you and best regards m8 |
Code:
ssh user@localhost echo '\"asdsd\"' |
no, it is not working for me...
tnx |
You have to escape the double quotes, but you must protect both the escape character and the double quotes from the local shell. Example:
Code:
ssh user@host "sed -i '12s/.*/few_words=\\\"$w\\\"/' /path/to/file" |
yesssss!!!!
Thank you so much colucix, you are my savior! Respect and best regards m8 |
You're welcome! :)
|
All times are GMT -5. The time now is 12:45 AM. |