jmhorner,
@jmhorner@eattherich.club avatar

Is there a way to automate opening a bunch of frequently used SSH sessions all at once on a Linux based workstation? I'd like to type a single command and wind up with a single terminal window having three tabs.

  • Tab 1 would be labeled "web-logs" and would [upon connection] have a "tail -F" of my nginx logs.

  • Tab 2 would be labeled "mail-logs" and would [upon connection] have a "tail -F" of my postfix logs.

  • Tab 3 would be labeled "lily" and would have a typical interactive session to my minetest server.

I am currently using Asbru Connection Manager which works great, but I'd like to think I could do this with a simple terminal window. Am I wrong?

jmhorner,
@jmhorner@eattherich.club avatar

Thanks a bunch @tkk13909 @Binder @godber @eletious @LovesTha @Mayabotics @argv_minus_one @oblomov

Hopefully I didn't miss anyone. This is an example of what my little xdotool script does right now. I am going to run it side-by-side with asbru for a bit and see how it works out. The general idea of the script is:

xdotool key ctrl+shift+t
xdotool key ctrl+shift+i
xdotool type lily-mail
xdotool key KP_Enter
xdotool sleep 0.5
xdotool type 'ssh user@box'
xdotool key KP_Enter
xdotool sleep 1
xdotool type 'tail -F /path/logfile'
xdotool key KP_Enter

An lxterminal window running a script that opens up multiple tabs, names each tab, and opens an ssh session within each tab.

tkk13909,
@tkk13909@fosstodon.org avatar

@jmhorner @Binder @godber @eletious @LovesTha @Mayabotics @argv_minus_one @oblomov looks like you've got it figured out!

jmhorner,
@jmhorner@eattherich.club avatar

@tkk13909 @Binder @godber @eletious @LovesTha @Mayabotics @argv_minus_one @oblomov

I hope so... it is still a little clumsy though. For example, I am finding that one of my servers is slightly slower than the others to respond and I have to adjust the delays between typing. So if I had a server down or a significant delay, the xdo "typing" has no way to "notice" the problem and slow itself down.

argv_minus_one,
@argv_minus_one@mstdn.party avatar

@jmhorner

Yeah, those delays make it uncomfortably sensitive to timing. It'll also break if you type anything else on the keyboard while it's running. And it won't work on Wayland.

If you haven't already, you might want to check if LXTerminal has a command-line option or D-Bus API to add new tabs and run specific commands on them, like Konsole does. If so, that would avoid all the issues with the xdotool approach.

jmhorner,
@jmhorner@eattherich.club avatar

@argv_minus_one lxterminal DOES have command line args to open a new tab, in fact multiple tabs... however, there does not seem to be a way to inject a command in to more than one of those tabs. Which strikes me as quite odd. It would be awesome if I could just run

lxterminal -t "box1" -e "command" -t "box2" -e "command"

argv_minus_one,
@argv_minus_one@mstdn.party avatar

@jmhorner If it opens new tabs in an existing window, could you not just run lxterminal three times, once for each tab?

jmhorner,
@jmhorner@eattherich.club avatar

@argv_minus_one It is weird...

lxterminal --tabs="box1, box2, box3"

Opens a new window with three tabs with the custom names.

lxterminal --tabs="box1, box2, box3" -e "ssh mishka"

Opens a new window with the same-named tabs and an SSH session to mishka in "box1".

lxterminal --tabs="box1, box2, box3" -e "ssh mishka" -e "ssh pansy"

Opens the same tabs with box1 broken... a hung blank box with no text and no session.

lxterminal --tabs="box1, box2, box3" --command="ssh mishka" --command "ssh pansy"

Gives the three tabs, a session to mishka in box1 and a plain local terminal in box2.

lxterminal --tabs="box1, box2, box3" --command="ssh mishka, ssh pansy"

Gives me just box2 and box3. I assume box1 treats both SSH commands as one, fails, then exits.

$ lxterminal --tabs="box1" --command="ssh mishka"
$ lxterminal --tabs="box2" --command="ssh pansy"

Run as two separate commands in a single terminal window, gives me the desired sessions but they are in their own windows rather than tabs.

Hold on a sec here... of course this is all within lxterminal. I am fartin' around with xfce4-terminal and there MAY be a way. Update pending. :-)

jmhorner,
@jmhorner@eattherich.club avatar

@tkk13909 @Binder @godber @eletious @LovesTha @Mayabotics @argv_minus_one @oblomov

I should also mention that my "old" solution [Asbru Connection Manager] actually does use regexp strings for "expected replies" and has default ones with sane values that allow it to compensate and provide a much smarter and more interactive type of login process.

jmhorner,
@jmhorner@eattherich.club avatar

@tkk13909 @Binder @godber @eletious @LovesTha @Mayabotics @argv_minus_one @oblomov

After continuing to fiddle today, I think this method with xfce4-terminal may work out best long term...

https://snork.ca/posts/2023-09-30-favourite-ssh-sessions-automation/

Huzzah!

LovesTha,
@LovesTha@floss.social avatar

@jmhorner @tkk13909 @Binder @godber @eletious @Mayabotics @argv_minus_one @oblomov

"xdotool type 'ssh user@box'
xdotool key KP_Enter
xdotool sleep 1
xdotool type 'tail -F /path/logfile'"

could be:
"xdotool type 'ssh user@box tail -F /path/logfile'

And that has no time dependency.

jmhorner,
@jmhorner@eattherich.club avatar

@LovesTha @tkk13909 @Binder @godber @eletious @Mayabotics @argv_minus_one @oblomov

I actually tried it that way and it would only tail the last ten lines (yes I had a -F) and then exit. With the little one-line script on the server it works fine for some reason. :-(

LovesTha,
@LovesTha@floss.social avatar

@jmhorner @tkk13909 @Binder @godber @eletious @Mayabotics @argv_minus_one @oblomov

Something is weird in your setup, that works fine for me.

maybe:
"xdotool type 'ssh user@box bash -c 'tail -F /path/logfile'''"

Which is getting awkward with so many quotes needed.

jmhorner,
@jmhorner@eattherich.club avatar

@LovesTha @tkk13909 @Binder @godber @eletious @Mayabotics @argv_minus_one @oblomov

My setup is pretty basic... a Devuan base install, xorg and openbox, with lxterminal. I just tried a bunch more combinations with various quotes and couldn't get it to go at all. :-(

LovesTha,
@LovesTha@floss.social avatar

@jmhorner @tkk13909 @Binder @godber @eletious @Mayabotics @argv_minus_one @oblomov Bit of a silly option but still more reliable than sleeps: setup an account on the server that has the tail in their .bashrc?

Lunatech,

@jmhorner I think Tabby may have a way to do this, or at least reopen the last group of tabs you had open when you last ran the program ("Restore terminal tabs on app start" setting).

oblomov,
@oblomov@sociale.network avatar

@jmhorner I think this should be possible with tmux, ssh-agent, key-based authentication and the ssh remote command feature.

jmhorner,
@jmhorner@eattherich.club avatar

@oblomov Of course I can establish an easy-to-connect single session with just key based auth and a ~/.ssh/config file. The trouble is in getting new tabs to open in my terminal window, each with a specific tab-name and a different SSH connection in it. tmux tabs exist, but are [IMO] clumsy compared to term window tabs. I'm sure there are CLI lovers who would call me lazy for not wanting to commit tmux tab navigation keystrokes to muscle memory, but term window tabs work, they work right now, and they work the same way tabs work in a plethora of other applications that everyone™ has been using for a long time. :-)

oblomov,
@oblomov@sociale.network avatar

@jmhorner you'll have to check if and how your terminal app is scriptable. For tmux, if it's just a matter of muscle memory, you can reconfigure the tmux key bindings.

argv_minus_one,
@argv_minus_one@mstdn.party avatar

@jmhorner

You can do that in with konsole --tabs-from-file.

You'll need to write a “tabs configuration file” with the tab names and commands that you want. See the manual https://docs.kde.org/stable5/en/konsole/konsole/command-line-options.html and scroll down to the --tabs-from-file section.

Then just make a .desktop file that runs konsole --tabs-from-file /path/to/tab/configuration/file, and that should do it.

jmhorner,
@jmhorner@eattherich.club avatar

@argv_minus_one I am actually running a pretty slim GUI with just Openbox and figured Konsole would be a ridiculous pile of dependencies but a quick check gives me the impression it really wouldn't be that bad. I am currently seeing if I can make a go of it with xdotool but may try Konsole if it fights me.

argv_minus_one,
@argv_minus_one@mstdn.party avatar

@jmhorner Limited hardware?

jmhorner,
@jmhorner@eattherich.club avatar

@argv_minus_one No, just a goof who thinks anything more than a solid colour background is a waste. I think the best desktop environment is the one you don't even notice.

I mean my decade old laptop is probably considered limited hardware by many people's standards, but it is plenty for me. Perhaps not a popular opinion, but it's all I got. :-)

argv_minus_one,
@argv_minus_one@mstdn.party avatar

@jmhorner

My background is almost a solid color. It's the dot-pattern background from Macintosh System 7. It's a 2×2-pixel PNG, weighing in at a staggering 87 bytes!

Now if only I could make the Plasma panel do the rounded-corner thing that System 7 did.

Anyway, if you ever feel like running full Plasma for some reason, it'll probably work on your machine. I have it running fine on a laptop of similar age (Core 2 Duo, 4GB RAM).

jmhorner,
@jmhorner@eattherich.club avatar

@argv_minus_one

"dot-pattern background"

Sweet. :-)

Right now I have a script with a bunch of xdotool commands that works, but is a little slow. In the morning I'll see how much I can shave off the time-to-open. I'm not sure I'll stick with xdotool in the end, but it does work with my term of choice and MAY let me get rid of asbru. Not that asbru sucks, I just think it would be nice if I could replace it with "something I already have".

LovesTha,
@LovesTha@floss.social avatar

@jmhorner tmux/screen/byobu/etc can do this sanely with a default or selected config where windows are started with various ssh commands (and others for a common repeatable console session setup)

jmhorner,
@jmhorner@eattherich.club avatar

I guess I should add that I prefer to do this in lxterminal or xfce4-terminal, but am willing to consider another terminal that would result in less resource use and fewer child processes as Asbru. :-)

godber,
@godber@az.social avatar

@jmhorner I did this kind of thing with screen or tmux configuration. Launch a screen session that in turn opens the ssh connections which then run the commands.

Additionally I’d have the session detach after five minutes of idle time. This allowed me to reconnect in any other terminal session without having to find the right one.

eletious,
@eletious@eattherich.club avatar

@godber @jmhorner Seconding tmux, it's so nice. plus you can customize how the status bar looks

jmhorner,
@jmhorner@eattherich.club avatar

@eletious @godber @LovesTha

I have tried tmux and screen in the past but didn't really like them. My recollection was that when I tested them the tail'ed log files did not "record" log entries that happened while disconnected from the session but a test right now worked fine. Trouble is, with tmux (and related) I still have to [in lxterminal]:

  • CTRL-SHIFT-T to open a new tab
  • CTRL-SHIFT-I and type in the name of the new tab
  • ssh to box1
  • CTRL-SHIFT-T to open a new tab
  • CTRL-SHIFT-I and type in the name of the new tab
  • ssh to box2
  • CTRL-SHIFT-T to open a new tab
  • CTRL-SHIFT-I and type in the name of the new tab
  • ssh to box3

That is really the part I am having the most trouble automating.

LovesTha,
@LovesTha@floss.social avatar

@jmhorner @eletious @godber That is all 100% automatable

As a one liner something like:

tmux \
new-session -s "watchers" -n "topper" 'top' ; \
new-window -n "glancer" 'glances' ;

should be a useful start.

jmhorner,
@jmhorner@eattherich.club avatar

@LovesTha @eletious @godber

I'm not sure I get ya... is this supposed to open multiple tabs in my terminal window?

LovesTha,
@LovesTha@floss.social avatar

@jmhorner @eletious @godber Yes, that gives you a tab named 'topper' with 'top' running and a tab named 'glancer' with 'glances' running (if you don't have glances installed that wont work)

'ctrl+b, n' switches between the tabs.

LovesTha,
@LovesTha@floss.social avatar

@jmhorner @eletious @godber Bottom left of the terminal window should have:
[watchers]0:topper- 1:glancer*

That indicates that:
The tmux session is titled "watchers" (used to reconnect to that tmux session)
Window 0 is titled 'topper'
Window 1 is titled "glancer'

jmhorner,
@jmhorner@eattherich.club avatar

@LovesTha @eletious @godber

No no... I don't want to use tmux tabs, I want actual tabs in my terminal window.

eletious,
@eletious@eattherich.club avatar

@jmhorner @LovesTha @godber ohhh, interesting. i don't know for sure, but it probably depends on your terminal emulator - i bet byobu would do exceptionally well in this case

LovesTha,
@LovesTha@floss.social avatar

@jmhorner @eletious @godber sorry, I went the tmux route as you wanted to type a command and that your current GUI based way wasn't good for you.

jmhorner,
@jmhorner@eattherich.club avatar

@LovesTha @eletious @godber

Not so much that my current GUI based way isn't working for me, but more that it seems to be a feature that nobody wants.
From what I can find, old versions of gnome-terminal (as mentioned by @Mayabotics) actually used to have this ability, but it has since it removed. I didn't test "old version gnom-terminal" but was able to find descriptions of how people used it to accomplish what I am looking for. I'm also familiar with KiTTY, unfortunately it is a Windows-only application.

I guess it seems weird to me that it isn't a much more common request. I'll get to work shortly on trying to improve my xdotool script and see what I can come up with.

Binder,
@Binder@petrous.vislae.town avatar

deleted_by_author

  • Loading...
  • Private
    tkk13909,
    @tkk13909@fosstodon.org avatar
    tkk13909,
    @tkk13909@fosstodon.org avatar

    @jmhorner I'm not home right now but once I'm back at my computer I'll see if I can figure out a script for ya.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ethstaker
  • DreamBathrooms
  • cubers
  • mdbf
  • everett
  • magazineikmin
  • Durango
  • Youngstown
  • rosin
  • slotface
  • modclub
  • kavyap
  • GTA5RPClips
  • ngwrru68w68
  • JUstTest
  • thenastyranch
  • cisconetworking
  • khanakhh
  • osvaldo12
  • InstantRegret
  • Leos
  • tester
  • tacticalgear
  • normalnudes
  • provamag3
  • anitta
  • megavids
  • lostlight
  • All magazines