Im trying to do log into a file (in a remote server lets say /home/test/log.txt) what is stored in $var. Im trying with
ssh test@$192.168.1.35 "echo "var" >> /home/test/log.txt"
y also tried
ssh test@$192.168.1.35 "echo "$var" >> log.txt"
but the both didnt work
any help?
You’re using double quotes, so the variable expansion will happen locally. You should use single quotes, so that the command gets sent unaltered.
In the same way as
echo '$var'gives$varwhileecho "$var"displays the contents, this way the server sees$varinstead of the contents of the local$var.So:
ssh test@$192.168.1.35 'echo $var >> /home/test/log.txt'will create a file on the remote computer, with the value of the remote
$varin it.If you do
ssh test@$192.168.1.35 'echo $var' >> /home/test/log.txtyou get a file on the local computer with the value of the remote
$varin it.If you do
ssh test@$192.168.1.35 "echo $var >> /home/test/log.txt"it stores the value of your local
$varin the file on the remote system.(Also, if it only involves the remote system, you should probably use a shell script, or maybe cron if you want it to happen automatically.)