I wrote a script test.sh (its function is the same as "hostname" command) as below,
#!/bin/bash
printf "`uname -a | awk '{print $2;}'` "
I can get my hostname with
source /home/arton/test.sh
or
/home/arton/test.sh
Then, I issued the command
ssh myhost "source /home/arton/test.sh"
and expected getting "myhost", but I got total output of uname -a
Linux myhost 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 ...
After try and error, the commands below can output "myhost"
ssh myhost "/home/arton/test.sh"
ssh myhost "bash -s" < /home/arton/test.sh
But I still have no idea why this happens.
/home/arton/test.sh
, but sometimes to the same path on the remote machine? What is the remote user's shell? Is itcsh
maybe?