cd command not executed on grunt-ssh task

282 Views Asked by At

I'm running the task "grunt-ssh" github/ssh, and it works fine, except for the cd command, here is my code:

  grunt.initConfig({
      sshexec: {
          connect: {
            command: ['ls'],
            options: {
            host: 'some_host',
            username: 'user',
            password: 'pass'
         }
     }
 });

the output for this is for example is: /folder1, /folder2, /etc, /etc

but when I run the same task with e.g.:

command: ['cd /', 'ls'],

(the output it should be : /root, /foldera, /folderb, /etc, /etc) but instead of that i get the same : /folder1, /folder2, /etc, /etc it seem thet th command "cd /" i not executed.

Any ideas?

1

There are 1 best solutions below

0
On BEST ANSWER

I suspect that the cd command is executed, but in such a way that it doesn't affect the subsequent command. It's executed as its own process, so once it's done the next process starts off in exactly the same directory.

This should work:

        command: ['sh -c "cd /; ls"'],