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:
#!/bin/bash
PATH=$PATH:/bin:/usr/bin:Users/admin/.rvm/gems/ruby-2.2.4/bin:/Users/admin/.rvm/gems/ruby-2.2.4#global/bin:/Users/admin/.rvm/rubies/ruby-2.2.4/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/admin/.rvm/bin:/Users/admin/.rvm/rubies/ruby-2.2.4/bin/xcodeproj:/Users/admin/.rvm/rubies/ruby-2.2.4/bin/ruby
export PATH
And this is the line that is failing:
ruby generate_scheme.rb
Any help is appreciated, thank you.
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"'
Related
I am trying to export ROS_MASTER_URI from a shell script and then launch roscore. In my .sh file I have:
roxterm --tab -e $SHELL -c "cd $CATKIN_WS; $srcdevel; export ROS_MASTER_URI='http://locahost:1234'; roscore -p 1234"
When I do this, however, I get the following error in the roscore tab:
WARNING: ROS_MASTER_URI [http://locahost:1234] host is not set to this machine.
When I echo the ROS_MASTER_URI in this tab, it says that it is localhost:1234, which is correct. When I manually execute these commands, it works correctly and roscore launches without any issues. I am not sure why it does not work when launched from a bash file.
It was just a typo- missed the l in localhost. All working now.
Hi i have created a batch file (run.bat) that after execution connects me to UNIX server with help of plink. But issue starts from this point i have to execute a script after connection to my server the script contains a command sudo -l. After the execution i get the error as mentioned in subject can anyone help me on this issue ??
Batch File-:
"C:\Program Files\PuTTY" plink -ssh -pw Tos#12Ts w44dvftyw#caa1607UX009.wvd.abcd.net /opt/sieb/w44dvftyw/run.sh
Script file(run.sh) -:
#!/bin/bash
sudo -l
It says
sudo: command not found
But when i run my script normally on UNIX server it runs with no issues. What am i missing here to make it work this way please help.
Scripts such as ~/.profile or ~/.bash_profile responsible for setting up the current user's PATH are run only on login shells.
Running sh -c 'somescript' (as performed by ssh host 'somescript') is neither a login shell, nor an interactive shell; thus, it does not gain the benefit of such scripts.
This means that additions to the PATH (in your case, /usr/local/bin) may not be present with commands run in this way.
Among your options:
Pass the PATH you want as part of the command to remotely run. This might look like:
plink -ssh user#host "PATH=/bin:/usr/bin:/usr/local/bin /opt/sieb/w44dvftyw/run.sh"
Embed a working value in the script you're running:
#!/bin/bash
PATH=/bin:/usr/bin:/usr/local/bin
# ...put the rest of your script here.
I would like to run a command on a remote server using ssh, under bash, while my default session is csh.
minimal example (true command is more complex and is generated by my IDE remote debugger):
ssh hostname 'ls | head'
I don't have admin privileges. Trying chsh -s /bin/bash results with an error chsh: cannot lock /etc/passwd; try again later.
I tried adding to .cshrc the following
setenv SHELL /bin/bash
exec /bin/bash --login
but it freezes the console when sending the command through ssh (while regular ssh works)
Any idea how to solve that?
NOTE: I must have a solution that would configure the host, because I don't have access to the ssh command which is generated automatically by the debugger of my IDE. On the IDE I can only set the host name and port number. (EDIT) Therefore solutions like ssh hostname '/bin/bash -c "ls | head"' wont apply
EDIT2:
Actual command shown by IDE (again, I can't edit it):
ssh://username#localhost:2213/home/lab/username/anaconda2/envs/tf_011b/bin/python -u /specific/a/home/cc/cs/username/.pycharm_helpers/pydev/pydevd.py --multiproc --qt-support --client '0.0.0.0' --port 41823 --file /home/lab/username/remote_py/nlteach/show_attend_and_tell/train_saat_classifier.py --train_dir=/home/lab/username/nlteach/output/train/d=cub/imSD=11%imSP=rnd%tcSP=cvpr16/CSat/res50%lr0_02LrDTexpLrDc0_938OrmspWDc0/emb=512%ldTrn=0%nU=512%noHid=1%lr=0_02%lrDT=fix%lrDc=1%o=rmsp/
I am not sure why, but on a bash enabled server it works, while it fails on the csh host.
Thanks!
Invoke bash on the remote side, telling it what commands to run:
ssh hostname '/bin/bash -c "ls | head"'
If the command is too complicated (eg because of quotation mark escaping), then write your commands to a script, copy the script, then run the script:
scp script.bash hostname:/tmp/
ssh hostname '/bin/bash /tmp/script.bash'
Wondering if it is possible to automatically run a script or execute a command ONLY after vagrant ssh into the box? I understand that Ansible can provide beforehand installation and set up. But it failed to allow doing things automatically after entering the machine.
I am currently create a file script.sh. The file will be provided to the vagrant via Ansible. After I vagrant ssh into the box, I do bash script.sh to run the script. Is there better way?
Any suggestion would be more appreciated.
Two ways to achieve this,
Say assume your script is in vagrant home directory like,
:~$/home/vagrant/test-me.sh
1) Run command along with ssh
1a) vagrant ssh -- -t '/home/vagrant/test-me.sh; /bin/bash'
**-OR-**
1b) vagrant ssh -c '/home/vagrant/test-me.sh; /bin/bash'
2) Append complete script path in ~/.bashrc file (this should be in vagrant home directory if you are login as user vagrant)
:~$echo '. /home/vagrant/test-me.sh' >> ~/.bashrc
I am trying to run a ruby script as a service on my centos machine. I can run the ruby script direct from the command line and from a bash file without issue.
However, when I try to run it as a service via /etc/init.d I get the error 'require': cannot load such file -- somegem.
#! /home/user/.rvm/rubies/ruby-2.1.5/bin/ruby
# encoding: utf-8
require "somegem"
I have created an init.d script and placed that in /etc/init.d/
#!/bin/sh
# monitor_endpoint
# chkconfig: 2345 20 80
# Source function library.
. /etc/rc.d/init.d/functions
#Define variables
prog="monitor_endpoint"
exec=/home/user/Workspaces/test/bin/test.rb
echo $exec
start() {
echo -n $"Starting $prog: "
# use daemon to start the service
daemon $exec &
retval=$?
echo
return $retval
}
etc...
Would this be a problem with my gems installation path?
Any help would be much appreciated as this is my first attempt at running a ruby script in this way. Thank you.
the problem is in your environment (the env vars).
run
env
in the normal environment and after that run it from the init script and pipe the output to a file.
look at the differences.
GOing to guess you are missing all the ruby specific stuff(GEM_PATH and all)