running remote command with arguments and shell using ssh

1

I'm trying to execute a remote command using ssh.

I need the shell that executes the command to load .bashrc, so so far i've learned that i can use bash -lc for that. the problem is that it allows me to execute a command but ignore it's arguments

In general i want to run pm2 (Production process manager for Node.js) with a list parameter to show me the available running tasks.

when I execute

ssh ufk@10.0.0.3 bash -lc pm2 list

or

ssh ufk@10.0.0.3 bash -lc "pm2 list"

I get the same results. it executes the application as if i didn't provide any arguments at all.

here i provided the argument 'list' to pm2.

any ideas?

ufk

Posted 2015-08-04T09:01:07.257

Reputation: 1 055

You need a combination of strong and weak quotes around your bash statement. ssh ufk@10.0.0.3 "bash -lc 'pm2 list'" – fd0 – 2015-08-04T10:29:11.100

Answers

2

How about: ssh ufk@10.0.0.3 "bash -lc 'pm2 list'"

albal

Posted 2015-08-04T09:01:07.257

Reputation: 1 155

same results as before – ufk – 2015-08-04T10:30:23.480

ssh ufk@10.0.0.3 "bash -lc 'pm2 list'" works! :) thanks – ufk – 2015-08-04T10:30:59.980

@ufk, if you wanna use variables in the command, use "bash -lc \"$cmd\"" – theoden8 – 2015-08-04T12:07:44.127

how do i use pm2 form a remote shell script? i always get pm2: command not found – user137717 – 2016-06-29T02:05:19.330