Bash Prompt Below Output - Background Log Tail
Solution 1:
The following does what you need, without using tmux or screen or other programs. Keeps the prompt at the bottom. Replace "/var/log/cron" with whatever file you need:
#!/bin/bash
L=$(tput lines)
L1=${L}
(( L1-- ))
C=$(tput cols)
tput cup ${L} 0
tail -f /var/log/cron | while read line; do
tput sc
printf "\e[1;${L1}r\e[${L1};${C}f"
echo; echo ${line}
printf "\e[1;${L}r" && tput rc
done
the key to this are the ANSI control characters for the terminal. Particularly the "\e[x;y" statement which sets a new scrollable area. So, as each line of the log file is read, the bottom line in the window is excluded from the scrollable area, the line from the log file is inserted, then the bottom is added back in.
Solution 2:
The answer is screen or tmux is been used
I will explain how you could configure such using screen
1) Install screen using either apt-get install screen
on Ubuntu/Debian or yum install screen
RedHat derivates.
2) screen -S shell_and_logs
3) Then press Ctrl+a, followed by S
(capital S).
A horizontal screen will appear
4) Press Ctrl+a followed by TAB
This will jump to the second split window.
5) Create another window in here so you get the command prompt by pressing Ctrl+a release the keys then press c
6) You can resize the second windo by pressing Ctrl+a then typing :resize
after which Lines:
will appear. Enter the number of lines you want to show.
7) Finally you can switch between windows by Ctrl+a followed by TAB