Can I automatically execute a command on reattaching a detached byobu (screen or tmux) session?

Every time I login, /etc/motd is displayed. Since I hardly ever log out and in, I'd like to have the same functionality when reattaching to my detached session. This could be a simple cat /etc/motd kind of autostart.

  • Where it displays that? If you're running something (editor, for example) on your screen/byobu/..., how it should display contents of motd? – Olli Feb 6 '14 at 18:23
  • I guess you're right. Maybe that task would have to be done by the shell I'm running. – Thorsten Feb 6 '14 at 18:56
  • So you want that to happen every time you open a new shell? For example, new tab on screen, or before screen is reattached? (Something like "press enter to continue") – Olli Feb 6 '14 at 18:58
  • Before screen is reattached would do the job. – Thorsten Feb 6 '14 at 19:11
  • 1
    Related: unix.stackexchange.com/questions/5546/… – guntbert Oct 23 '16 at 20:42

I found a way to execute commands, not on reattaching but on idle: first I changed the byobu backend to screen, then I created a .screenrc in ~/.byobu containing

blankerprg  zsh -c "while true; do run-parts --lsbsysinit /etc/update-motd.d; sleep 30; clear; done"
idle        600 blanker

That uses screen's screensaver functionality to display text I would normally only see on login.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.