On Wed, 2008-12-03 at 15:32 -0800, Jim Lloyd wrote: > I'd like to so something that I bet savvy unix admins do all the time > with screen, but I haven't figured out the trick. > > I have a shell script that lets me do this: > > $ each <command> > > The script expands this running the same command on several machines: > > $ ssh host1 <command> > $ ssh host2 <command> > ... > $ ssh hostN <command> > > The script basically works fine, but it executes the commands > serially. For long running commands, I'd like to run them in parallel. > Ideally I'd run them in a detached screen session on each machine. The > ssh command should execute just long enough to start the long running > command in a detached screen session.
well, like perl people like to say : timtoady, if you don't like the solutions given in the thread, the simplest way with screen would be : -------------------------8<--------------------------8<---------------- ssh host1 "screen -dmS <sessionname>;screen -x <sessionname> -X screen <command>" ssh host2 "screen -dmS <sessionname>;screen -x <sessionname> -X screen <command>" ... ssh hostN "screen -dmS <sessionname>;screen -x <sessionname> -X screen <command>" ------------------------->8-------------------------->8---------------- you could also have all run in a local screen, so you see the outputs, but the commands don't get killed if your connection fails : -------------------------8<--------------------------8<---------------- screen -dmS <localsessionname> screen -x <localsessionname> -X screen 'ssh host1 "screen -dmS <sessionname>;screen -x <sessionname> -X screen <command>"' screen -x <localsessionname> -X screen 'ssh host2 "screen -dmS <sessionname>;screen -x <sessionname> -X screen <command>"' ... screen -x <localsessionname> -X screen 'ssh hostN "screen -dmS <sessionname>;screen -x <sessionname> -X screen <command>"' ------------------------->8-------------------------->8---------------- and you can manually enter all passwords, or use password-less keys to send all those commands without entering your password or use stuff : -------------------------8<--------------------------8<---------------- screen -x <localsessionname> -X screen 'ssh hostN "screen -dmS <sessionname>;screen -x <sessionname> -X screen <command>"' screen -x <localsessionname> -X stuff <password> ------------------------->8-------------------------->8---------------- and if you like the idea of running all ssh in one local screen, you can put all commands in your .screenrc (and use your favorite language to modify <command> or get <command> from argv). -------------------------8<--------------------------8<---------------- screen 'ssh host1 "screen -dmS <sessionname>;screen -x <sessionname> -X screen <command>"' screen 'ssh host2 "screen -dmS <sessionname>;screen -x <sessionname> -X screen <command>"' ... screen 'ssh hostN "screen -dmS <sessionname>;screen -x <sessionname> -X screen <command>"' ------------------------->8-------------------------->8---------------- > The -X option seems like it's intended for this purpose, but it seems > to be a no-op. The man page says "Note that this command doesn't work > if the session is password protected." To my knowledge the session is > not password protected, but perhaps I am misunderstanding this. well, it's just about ^a:password > Is there some simple recipe for using ssh to execute a command in a > detached screen on another host? hope it helps cheers, -- Guyzmo _______________________________________________ screen-users mailing list screen-users@gnu.org http://lists.gnu.org/mailman/listinfo/screen-users