1

Is it possible to make a bash script that starts tmux and split the screen horizontally and runs watch -n1 tail -n5 file_n in each ? Basically I'm starting a script multiple times and write its progress into different files that I'd like to monitor. Would be nice if I could run that from one script as opposed to manually open 10 files by myself. I never used tmux btw that's why I'm asking this.

  • 2
    Try to read the manual. – Ipor Sircer Dec 15 '16 at 17:16
4

Try this. It first establishes a detached tmux session, then opens your windows with tail commands, then sets the layout of the windows, then attaches to the session.

for f in `seq 1 10`; do
if [[ $f -eq 1 ]]; then
        tmux new-session -d -s my_session_name "watch -n1 tail -n5 file_${f}"
    else
        tmux split-window -d -t my_session_name:0 -p20 -v "watch -n1 tail -n5 file_${f}";
    fi
done
tmux select-layout -t my_session_name:0 even-vertical
tmux attach-session -t my_session_name

If you want to have multiple instances of this run, you need to change all the occurences of my_session_name to be something unique for each session.

Also, your title mentions 5 windows but the body of your post mentions 10 files. The code as-is will open 10 files in 10 windows. Change the seq 1 10 part for however many windows/files you actually want.

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.