June June -5 years ago 124
Ruby Question

Error running script on Mac OS but runs ok after ssh

I have a .sh script on a Mac OS machine to generate an IPA file using PhoneGap. If I log in the machine via ssh, and then run the script, it runs successfully. But if I try to execute it remotely, by doing an ssh and calling the script as below:

~$ ssh -i ~/.ssh/mykey admin@IP_ADDRESS 'cd /Users/admin/scripts && ./build.sh'

Then I get this error:

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- xcodeproj (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from generate_scheme.rb:2:in `<main>'

I have this on the beginning of the .sh file:



export PATH

And this is the line that is failing:

ruby generate_scheme.rb

Any help is appreciated, thank you.

Answer Source

Ssh by default establishes a non-login shell and therefore does not pick up whatever environment settings are in place for that user. Specifically, on your system it does not pick up settings for xcodeproj.

Use bash --login to establish a login shell:

ssh -i ~/.ssh/mykey admin@IP_ADDRESS -t 'bash --login -c "cd /Users/admin/scripts;./build.sh"'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download