简体   繁体   中英

When executing an SSH command in Jenkins, the bash profile is different to when connecting over SSH with the same user

I'm trying to run some CLI nodejs commands on a remote server using the Jenkins SSH exec functionality.

I'm receiving an error message when trying to run forever, which I had installed globally with npm.

Edit : the error was; -bash: forever: command not found .

Connecting over SSH as root and running which npm returns;

/root/local/bin/npm

Whereas via Jenkins, with the same command as root returns;

/usr/bin/npm

I've tried setting bash variables, but these seem to be inconsistent across the two connection mediums too.

Both were installed using the top method detailed here; https://gist.github.com/isaacs/579814#file-node-and-npm-in-30-seconds-sh

Try this:

ssh user@host -t 'bash -l -c "forever"'

You can read with man ssh :

If command is specified, it is executed on the remote host instead of a login shell.

No login shell no rc-files ( .bashrc , .bash_profile etc.) so probably no $PATH you expect to have.

To read more about the login shell check man bash and search for -l option explanation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM