grunt-ssh icon indicating copy to clipboard operation
grunt-ssh copied to clipboard

Can't seem to change directory

Open pmcatominey opened this issue 11 years ago • 11 comments

My attempts to use cd to change to the directory I wish to run further commands in does not appear to be working. The verbose log does not display much either.

image

pmcatominey avatar Aug 03 '13 22:08 pmcatominey

Looks like its because each command is running in a separate session. When a session is ended (Stream :: exit), it will lose the current directory.

How are you running it? Can you try something like this:

sshexec: {
  test: {
    command: ['pwd', 'cd /tmp', 'pwd'],
    options: {
      config: 'myhost'
    }
  }
}

I think that should work.

Otherwise, a work around might be:

sshexec: {
  test: {
    command: 'pwd; cd /tmp; pwd',
    options: {
      config: 'myhost'
    }
  }
}

andrewrjones avatar Aug 06 '13 13:08 andrewrjones

Yeah, I have the same issue. Doing command: ['pwd', 'cd /tmp', 'pwd'] is always in /root.

In command: 'pwd; cd /tmp; pwd', works, but is no cool.

Tks

favio41 avatar Aug 23 '13 10:08 favio41

Same issue for me. Commands chaining using array would be a very appreciated feature for automated deployment.

noirbizarre avatar Sep 17 '13 08:09 noirbizarre

Yeah, I agree. This would be a good feature.

The execCommand function is taking one command at a time (using command.shift()) and passing this to ssh2's exec function. As we are not closing the connection until all commands are finished, I had hoped that any changes to the environment would be kept, but that doesn't seem to be the case.

Maybe we need to use the shell() function from ssh2 instead. This could be a separate task, as it will behave differently to exec.

andrewrjones avatar Oct 15 '13 11:10 andrewrjones

Anything new about that ? It is really a needed feature since the cwd is very important to develop/deploy.

marvinroger avatar Nov 20 '13 19:11 marvinroger

I get around this by creating bash script file, use sftp to copy it over and then sshexec to chmod and run it. Much neater than placing a bunch of shell commands in a JS array.

On Wednesday, November 20, 2013, Marvin Roger wrote:

Anything new about that ? It is really a needed feature since the cwd is very important to develop/deploy.

— Reply to this email directly or view it on GitHubhttps://github.com/andrewrjones/grunt-ssh/issues/24#issuecomment-28919610 .

David J. Bradshaw )'( [email protected]

'The people we think are a little weird are the ones who change the world'

  • Simon Sinek

davidjbradshaw avatar Nov 20 '13 21:11 davidjbradshaw

Didn't even think about that ! Thanks a lot for the idea. :)

marvinroger avatar Nov 20 '13 21:11 marvinroger

You might also want to check out grunt-hash-manifest to checksum the files your uploading. I had a tar.gz file get corrupted the other week and it trashed a load stuff when I tried to untar it.

The version of grunt-hash-manifest on NPM has a bug in it when dealing with binary files, I've fixed it and sent a pull request, but the project seems a bit dead, so you might want to use my fork for now.

https://github.com/davidjbradshaw/grunt-hash-manifest

I've also written a couple of shell scripts to check the manifest file on the remote server.

https://gist.github.com/davidjbradshaw/7438465

davidjbradshaw avatar Nov 21 '13 13:11 davidjbradshaw

It might be useful for some sensitive environments. Thanks again !

marvinroger avatar Nov 21 '13 21:11 marvinroger

Just a quick thought:
An easy way to use an array of commands

myTask {
    command: ['cd my/path', 'ls -la'].join(';')
}

aarontropy avatar Apr 15 '14 15:04 aarontropy

Thanks @aarontropy :+1:

brunowego avatar Mar 17 '15 20:03 brunowego