duncs / clusterssh

Cluster SSH - Cluster Admin Via SSH
https://github.com/duncs/clusterssh/wiki
897 stars 79 forks source link

ClusterSSH should support picking a working directory for each terminal #42

Closed purpleidea closed 8 years ago

purpleidea commented 8 years ago

It would be great if there was a way to pick the working dir to start in for each terminal.

Tests like including:

--action 'screen -xRR'

work just fine, but things like:

--action 'cd /tmp && screen -xRR'

don't work at all... Not sure why actually.

It would expand upon the functionality added to the other tools in this commit:

https://github.com/purpleidea/oh-my-vagrant/commit/ed32d70e20f02f8258286c24a3e7617f4d062c0f

Thanks in advance for any suggestions and fixes!

duncs commented 8 years ago

Can you please provide details on the error you get. I have run a test as follows:

$ cssh --debug --action "cd /tmp && pwd && cd /var && pwd" localhost:22

and I get the expected output in the terminal window that opens:

Running: ssh -x -o ConnectTimeout=10 -p 22 localhost "cd /tmp && pwd && cd /var && pwd" ; echo Sleeping for 5 seconds; sleep 5
/tmp
/var
Sleeping for 5 seconds

Duncs

purpleidea commented 8 years ago

@duncs aha, so I played around a bit more and while I couldn't get your example to work with screen, it did work, and I realized the issue was something else... If I run:

cssh --debug --options "-t" --action "cd /tmp && pwd && cd /var && pwd && screen -xRR" vagrant@192.168.121.228:22

including the -t option made it all happy :)

However, I still have the problem that there isn't a way to specify a different action (and/or different working directory) PER terminal... So either we would need a --action-machine1 --action-machine2 type option, or similar... Any recommendations?

duncs commented 8 years ago

I'm currently considering adding a config file option that changes the directory the terminal is started in, possibly using macros to work out the path

Terminal_chdir = /tmp/cssh-%n

Or similar. If it isn't defined then it works as now. Would that work for you?

Duncs

On 1 Oct 2015, at 08:44, James notifications@github.com wrote:

@duncs aha, so I played around a bit more and while I couldn't get your example to work with screen, it did work, and I realized the issue was something else... If I run:

cssh --debug --options "-t" --action "cd /tmp && pwd && cd /var && pwd && screen -xRR" vagrant@192.168.121.228:22 including the -t option made it all happy :)

However, I still have the problem that there isn't a way to specify a different action (and/or different working directory) PER terminal... So either we would need a --action-machine1 --action-machine2 type option, or similar... Any recommendations?

— Reply to this email directly or view it on GitHub.

purpleidea commented 8 years ago

On Sat, Oct 3, 2015 at 9:58 AM, Duncan Ferguson notifications@github.com wrote:

I'm currently considering adding a config file option that changes the directory the terminal is started in, possibly using macros to work out the path

Terminal_chdir = /tmp/cssh-%n

Or similar. If it isn't defined then it works as now. Would that work for you?

Duncs

Might need slightly more information on how to use this from the CLI, but assuming you can specify different dirs for each window that way, then this works for me. Bonus points if your patch to cssh comes with a patch to vcssh ;)

Thanks for looking into this! Cheers, James

duncs commented 8 years ago

Done and pushed to the code repository - added two new settings to ~/.clusterssh/config

terminal_chdir = 1
terminal_chdir_path = $HOME/.clusterssh/work/%s

Will be released in 4.04_01.

No patch for vcssh should be required as its all in the config file.

purpleidea commented 8 years ago

w00t, thanks again for looking into this...

@duncs I appreciate the path, but I'm not 100% sure how I would use this... My understanding is that this requires use of a standalone config file. So it's not a problem for me to generate that per working directory and use --config-file=, but in that file, I suppose I have to add the two settings like this:

terminal_chdir = 1
terminal_chdir_path = path-to-the-working-dir/%s

where %s is an additional file name (where %s is) and that contains the path string I want for that server?

Or does this work differently...

Thanks for clarifying!

duncs commented 8 years ago

The configuration is set in the 'global' configuration file and therefore affects every session ($HOME/.clusterssh/config). You could if necessary create a suplimental config file and pull that in through the use of '-C ' but it isnt necessary.

As per the docs, the %s is the macro for 'server name' for the conneciton (the same as is used in the title of the terminal windows) and is substituted in for each terminal, so for Svr1 and svr2 the path becomes

/svr1/ /svr2/ Each terminal session creates this directory on the server side and then changes into it before making the connection to the server Does that make more sense, now?
duncs commented 8 years ago

After relooking at this issue, I believe the change of directory is the wrong side of the connection (it is server side, not client side).

I will re-evalute what is required.

duncs commented 8 years ago

I have removed the 'terminal_chdir' code as it did not resolve the issue.

However, other code added as aprt of this release means '--action' is passed through macro parsing, so you can: cssh --action 'mkdir /tmp/%s ; cd /tmp/%s ; pwd ; sleep 10' host1 host2 host3 shows a different directory is used for each host. See the man page for the different available macros.

This is now available in the git repo.

Duncs