Sunday, April 3, 2011

Use Remote Variables with Rsh or Ssh

Followng are the difference between local and remote variables. $PWD is the local variable passed to remote system, but \$PWD is the variable defined in the remote system.

/home/patrickw/tools $ sudo ssh host "echo $PWD"
/home/patrickw/tools

/home/patrickw/tools $ sudo ssh host "echo \$PWD"
/root

Therefore, backslashes in the following example is necessary. Without the backslashes, awk will complain syntax error since the variables are blank.

sudo ssh host "top -b -n 1 | egrep sudo\|ssh\|xinet | awk '{print \$1, \$9, \$10, \$12}'"

No comments: