1

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.

4
  • I cannot reproduce your problem, it works fine on my system. Jun 17, 2015 at 7:46
  • I always get the output of "uname -a" when I issue the command: ssh myhost "source /home/arton/test.sh". Don't know if the env will affect the behavior or not.
    – Arton
    Jun 17, 2015 at 8:28
  • 1
    Are you aware you sometimes refer to the local file /home/arton/test.sh, but sometimes to the same path on the remote machine? What is the remote user's shell? Is it csh maybe? Jul 31, 2018 at 6:59
  • Yeah, I am aware I refer to the same path on the different host, but all the hosts in our local network mount the same file system. You are right! The logging shell is csh, and it is the problem. I tested the script with bash when I posted the question. I should have used ssh myhost "/home/arton/test.sh" instead of ssh myhost "source /home/arton/test.sh".
    – Arton
    Aug 1, 2018 at 10:01

0

You must log in to answer this question.

Browse other questions tagged .