Lurker News
I read a similar thread on reddit (https://www.reddit.com/r/AskReddit/comments/4v3ts4/what_was_your_why_didnt_i_start_doing_this_sooner/) and thought that it would be interesting to know such moments from the HN community!

Comments (767) 174 threads

Show all comments

Showing thread 48 of 174

_iyrr1 reply#
Using screen in daemon mode.

    screen -dmS myservice /blah/start.sh
Fit that line somewhere in a properly constructed init.d file and you're good to go. And if you need to execute a safe stop from that program through some interactivity:

    screen -S myservice -X stuff "stop\n"
And voila. It sends a line of text over followed by an enter key. Elegant, useful. You can reattach session to see what's happening at any time. Love me some screen.

When the process exits in that screen session, screen session is closed so that you can rely on screen -list.

zzalpha2 replies#
Not to start a flamewar, but have you looked at tmux for this kind of thing?

"Daemon mode" is the mode for tmux, and the whole stack is designed to be extremely scriptable. "tmux send-keys" does what you're referring to, here, but essentially anything you can do interactively, you can do via the command-line.
Not to say you shouldn't just keep doing what works for you! But figured I'd at least make mention of tmux as an alternative... I'm a fan. :)

atemerev3 replies#
Ctrl-B is the _worst_ shortcut ever devised (which is why it is used rarely... except on tmux). Just _thinking_ about it gives me the pain. My hand hurts.

And yet, this is a default shortcut for command mode in tmux. "But you can configure it!" — one might say. No, I won't be doing it on every system I manage, I have better things to do.

zzalpha#
Eh, fair enough. I just reconfigure it and move on, but I grant you that doesn't necessarily work for everyone. shrug
reedlaw#
Have you ever tried using the alt/ctrl/shift keys on the other hand side? So for Ctrl-B you would use the right-hand pinky to hit ctrl and the left-hand index finger to hit B.
daveloyall1 reply#
One of my "Why didn't I start doing this sooner?!" moments was copying my config files to all my machines.

It all started with less(1)... Configuring it is a pain in the butt. One day, I couldn't remember how to do it on a new machine, so I just performed the following command...

    scp ~/.*less* ~/*less* newmachine:
It was wonderful! Now I do the same thing for my emacs config, and my .xsession, and my hosts files, etc.

Continue this thread — 1 reply

_iyrr#
Many ways to accomplish the same thing in Linux, starting with a popen() call. ;) so thanks for pointing out tmux.

Since I use screen fairly often, it had never occurred to me (until fairly recently) that you can rely on it to start with a machine reboot -- and yet have the very familiar interface available to you when you want to intervene. Something to be said about muscle memory.