Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shell script for byobu commands

Need to write a shell script that opens byobu terminal with separate tabs. First line opens new byobu session and subsequent lines connect to that session and open new tabs. Its kind of automate opening terminal.

Ex -

byobu new-session -s "Server" "redis-server"

byobu new-window "redis-cli"

byobu new-window "sudo mongod --port 27017 --dbpath /data/db/rs0 --replSet rs0"

byobu new-window "mongo"

Problem here is when I run once this shell script it runs only first command and then stops. If I run it again then it executes the remaining lines with the message:

duplicate session: Server

What am I doing wrong here ?

like image 489
Amit Yadav Avatar asked Apr 27 '17 15:04

Amit Yadav


People also ask

What is byobu terminal?

Byobu is an enhancement for the GNU Screen terminal multiplexer or tmux used with the Linux computer operating system that can be used to provide on-screen notification or status, and tabbed multi-window management. It is intended to improve terminal sessions when users connect to remote servers.

How do I open a byobu session?

Start a new session by pressing CTRL+SHIFT+F2 , then use ALT+UP and ALT+DOWN to move backwards and forwards through your open sessions. You can press CTRL+D to exit Byobu and close all of your sessions. If you instead want to detach your session, there are three useful ways to do this.

How do you detach byobu?

We can disconnect from the byobu session by hitting F6.


1 Answers

I think you are missing the first line from your shell script. See if this works

#!/bin/sh
# byobu_launcher.sh ver 20170915122301 Copyright 2017 alexx, MIT Licence ver 1.0

byobu new-session -d -s $USER

# redis window
byobu rename-window -t $USER:0 'redis-cli'
byoby send-keys "redis-cli" C-m
byobu split-window -v

# mongod
byobu new-window -t $USER:1 -n 'mongod'
byobu send-keys "sudo mongod --port 27017 --dbpath /data/db/rs0 --replSet rs0" C-m

# mongo
byobu new-window -t $USER:1 -n 'mongo'
byobu send-keys "mong" C-m

# Set default window as the dev split plane
byobu select-window -t $USER:1

# Attach to the session you just created
# (flip between windows with alt -left and right)
byobu attach-session -t $USER

with screen you can do this by adding to the end of ~/.screenrc

screen -t redis-cli 0
stuff "redis-cli\n"
screen -t mongod 1
stuff "sudo mongod --port 27017 --dbpath /data/db/rs0 --replSet rs0\n"
screen -t mongo 2
stuff "mongo\n"
select 1

I mostly use screen and sometimes use tmux. I haven't used byoby.

like image 162
Alexx Roche Avatar answered Oct 11 '22 11:10

Alexx Roche