I'm running a bash script that creates an Xpanes and Tmux sessions based on list of hosts (SSH to each host in the list with some extra arguments).
The issue now is that every xpanes command is created in a different window instead of one window with split panes.
If I'm running the same command separately (not via the script) it is work as excepted.
What am i missing here? or how can i attached all those windows to one splitted window?
Here is my code:
#!/bin/bash
#validate if TMUX session is running
if ! [ -n "$TMUX" ]; then
echo "This must be run from a Tmux session, please create a Tmux session first"
exit 0
fi
set +x
for srv in `cat hostsList.txt`; do \
echo "[$srv]"
RAND=`echo $srv | md5sum | awk '{print $1}'`
cp ~/.ssh/id_rsa{,_$RAND}
cp ~/.ssh/id_rsa{.pub,_$RAND.pub}
xpanes -c "{}" "<my SSH command>" ;
rm ~/.ssh/id_rsa_$RAND ~/.ssh/id_rsa_${RAND}.pub &
done
I have this that is working pretty good in openwrt:
#!/bin/sh
#set -x #debug
while true; do
wget -O /tmp/extip 'http://ifconfig.me/ip' 2>/dev/null
EXT_IP=$(cat /tmp/extip)
INT_IP="$(ip addr show dev wwan0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)"
ROOTER=/usr/lib/rooter
[ -z $EXT_IP ] && continue
if [ $(echo "$INT_IP" | grep "$EXT_IP" -q; echo $?) -eq 1 ]; then
/sbin/ifup wan1
$ROOTER/pwrtoggle.sh 1
echo "NAT-DETECT: External ($EXT_IP) does not match Internal ($INT_IP); Reconnecting WAN1..." > /dev/kmsg
/etc/init.d/firewall restart
/etc/init.d/miniupnpd restart
fi
sleep 30
done
#set +x #debug
How do I make this script run in the boot (or after sometime) and let it running in background forever checking current IP status and doing its job? Also it looks like it's not good to have a init script with "sleep", because it's considered bad form. What would be an optimized form of this script to match my purpose?
Thanks in advance!
I installed GNU screen on my OpenWRT and in /etc/rc.local I have something like this:
# start screen in detached mode
screen -dm -S boot -c /dev/null bash /root/bin/monitor.sh
It will run in background. You can also attach to it with screen -r boot after login.
You can try if it works for you.
I write a simple shell script to help tmux show all the session in the status bar, however, the tmux's status bar always show the same thing in the different clients when they are all attached.
My script is as follows.
#!/usr/bin/env bash
session=`tmux ls | cut -d " " -f 1 | tr -d ":" | tr "\\n" " "`
# attached_count=`tmux ls | grep -n \(attached\) | cut -d ":" -f 1`
active_session=`tmux display-message -p '#S'`
# session_start="#[fg=brightblack,bg=black,nobold,noitalics,nounderscore]#[fg=white,bg=brightblack]"
session_start="#[fg=brightblack,bg=black,nobold,noitalics,nounderscore]#[fg=white,bg=brightblack]"
# session_end="#[fg=black,bg=brightblack,nobold,noitalics,nounderscore]#[fg=brightblack,bg=black,nobold,noitalics,nounderscore]"
session_end="#[fg=black,bg=brightblack,nobold,noitalics,nounderscore]"
session_active_start="#[fg=cyan,bg=black,nobold,noitalics,nounderscore]#[fg=black,bg=cyan]"
session_active_end="#[fg=black,bg=cyan,nobold,noitalics,nounderscore]"
session_str=""
count=1
for i in $session
do
# if [[ $count -eq $attached_count ]]; then
if [[ $i == $active_session ]]; then
session_str="${session_str}${session_active_start}${i}${session_active_end}"
else
session_str="${session_str}${session_start}${i}${session_end}"
fi
count=$((count+1))
# break
# echo "${i}"
done
session_str=`echo ${session_str} | tr -d "\n"`
printf "${session_str}"
```bash
It will output a long string content all my session name and make the attached one in other colors
"#[fg=brightblack,bg=black,nobold,noitalics,nounderscore]#[fg=white,bg=brightblack]besiii#[fg=black,bg=brightblack,nobold,noitalics,nounderscore]#[fg=brightblack,bg=black,nobold,noitalics,nounderscore]#[fg=white,bg=brightblack]conf#[fg=black,bg=brightblack,nobold,noitalics,nounderscore]#[fg=brightblack,bg=black,nobold,noitalics,nounderscore]#[fg=white,bg=brightblack]default#[fg=black,bg=brightblack,nobold,noitalics,nounderscore]#[fg=brightblack,bg=black,nobold,noitalics,nounderscore]#[fg=white,bg=brightblack]lang#[fg=black,bg=brightblack,nobold,noitalics,nounderscore]#[fg=cyan,bg=black,nobold,noitalics,nounderscore]#[fg=black,bg=cyan]vert#[fg=black,bg=cyan,nobold,noitalics,nounderscore]"
However, all my iterm windows which attach tmux's client will show the same status bar.
Is there a way to make tmux show different contents in different attached clients??
TL;DR: No.
Tmux sessions are designed to show exactly the same thing for all connected users. If a user is connecting on a small terminal, everyone's view will be squashed to only show the small terminal size. There is no way around that (unless you're viewing different windows in the same session), and there is no way to show different content to different users when viewing the same window.
I would like to start Firefox automatically on startup, and then maximize the window. With the code below, I am currently able to start Firefox, however I cannot get past that.
#!/bin/bash
firefox &
while [ "$(wmctrl -l | grep \"Mozilla Firefox\" 2>&1 | wc -l)" -eq 0 ];
do
sleep 1;
done
wmctrl -r firefox -b toggle, fullscreen
The first portion starts running Firefox. After that there is a loop, which I'm writing to create and display the Firefox window. The last step is maximize Firefox to full screen.
I believe I have a problem with the while loop.
I suggest:
while [[ $(wmctrl -l | grep "Mozilla Firefox" 2>&1 | wc -l) -eq 0 ]]; do
"screen -R -D -S test" will create a session named test if it doesn't exist, or connect to it if it does
"screen -d -m -S test" will create a new detached session named test, whether it exists or not, possibly leading to multiple sessions named test:
There are several suitable screens on:
9705.test (06/18/2012 06:42:58 PM) (Detached)
9639.test (06/18/2012 06:42:57 PM) (Detached)
How can I create a detached session named test, but only if one doesn't already exist?
I believe you're looking for the -d -R combination:
screen -d -R -S test
From man screen:
-d -R Reattach a session and if necessary detach or even create it
first
EDIT
If you just want to create a background screen only if it doesn't exist, a little shell function in your ~/.bashrc or ~/.zshrc will work:
function bgsc {
if screen -list | awk '{print $1}' | grep -q "$1$"; then
echo "screen $1 already exists" > &2
else
screen -d -m -S $1
fi
}
Then just call bgsc test.