I had to reboot my box today. I had several program running in tmux sessions. They seem to be still alive, how can I reattach to them?
I tried tmux a processID but it didn't work.
/home/me 21$ ps aux | grep tmux
me 1299 0.0 0.0 22244 1920 ? Ss Apr28 0:40 tmux -2 -f /tmp/r-plugin-me/tmux.conf new-session -s vimrpluginme1398670569alnn51oynp1vollnn51f2v4r_ied_delta1meRalphaCalibr VIMINSTANCEID=alnn51oynp1vollnn51f2v4r_ied_delta1meRal
me 2575 0.0 0.0 54164 3500 ? S 07:35 0:00 xterm -e tmux -2 -f /home/me/.tmux.conf -S /tmp/vX0qRrR/78
me 2577 0.0 0.0 19892 1400 pts/2 Ss+ 07:35 0:00 tmux -2 -f /home/me/.tmux.conf -S /tmp/vX0qRrR/78
me 2579 0.0 0.0 22128 1832 ? Ss 07:35 0:00 tmux -2 -f /home/me/.tmux.conf -S /tmp/vX0qRrR/78
me 5155 0.0 0.0 6380 756 pts/4 S+ 07:46 0:00 grep tmux
me 31340 0.0 0.0 23348 3000 ? Ss Apr28 0:17 tmux -2 -f /home/me/.tmux.conf -S /tmp/vIqEM06/78
You can not re-attach a process id. You need to reattach the corresponding tmux session.
So do tmux ls. Pick whatever session you want to re-attach. Then do tmux attach -d -t <session id> to re-attach it to a new tmux instance and release it from the old one.
If you only have one session detached you can just do
tmux attach
also if you're going to be working in multiple sessions it might be a good idea to name your sessions
tmux new -s ssh-to-staging
Ctrl b, d # Detach from session
tmux new -s ssh-to-s3
Ctrl b, d Detach from session
now when you do tmux ls you can reattach more easily without guessing.
tmux attach -d -t ssh-to-s3
You also might wanna bookmark this cheat sheet
Related
I am trying to create an automated clean shutdown of my opensimulator servers.
On each server, I have several Tmux sessions. Inside each session, there are several windows. In the following example, there are only two sessions to keep things simple.
sara#opensim:~$ tmux ls
Robust: 5 windows (created Tue May 12 22:08:28 2020)
Simulators01: 6 windows (created Tue May 12 23:30:38 2020)
sara#opensim:~$
In the full version, there will be 10+ Simulator sessions.
What I want to do is use a shell script to select a specific session. Every session will have a closedown shell script which looks similar to this:
#!/usr/bin/env bash
SESSION="InstancesTesting"
echo "checking for session - $SESSION"
SESSIONEXISTS=$(tmux list-sessions | grep $SESSION)
if [ "$SESSIONEXISTS" != "" ]
then
echo "session found"
tmux attach-session -d -t $SESSION
tmux select-window -t '0821'
tmux send-keys -t '0821' 'quit' C-m
tmux select-window -t '0900'
tmux send-keys -t '0900' 'quit' C-m
tmux select-window -t '0901'
tmux send-keys -t '0901' 'quit' C-m
tmux select-window -t '0910'
tmux send-keys -t '0910' 'quit' C-m
tmux select-window -t '0911'
tmux send-keys -t '0911' 'quit' C-m
tmux select-window -t '0920'
tmux send-keys -t '0920' 'quit' C-m
echo "finished shut down call for $SESSION"
else
echo "session not found skipping"
fi
The problem line is
tmux attach-session -d -t $SESSION
When it is run from a shell script, everything after that stops until the session is detached. However, without attaching the session only the windows of the last attached session can be accessed.
I can't simply kill the session at the end of the quit commands because the simular running inside each window can take up to 10 mins to shut down. Neither do I want to wait 10 mins between starting each shutdown. I want to set them all going then wait for the processes to close before doing a reboot.
What I need is to either:
1. Attach a session and allow the script to keep running without pressing ctrl+b D to detach.
or
2. Change the session which is being accessed without actually attaching it like the above example.
I have also tried
tmux switch-client SessionName
tmux switch-client -t SessionName
tmux switch-client -n
All of these return the same result
no current client
I have also tried
tmux send-keys -t 'WindowName' 'tmux choose-session' C-m
tmux send-keys -t 'WindowName' '0' C-m
Unfortunately, this option also states there is no client.
I am sure this must be possible, I am going round in circles, please help
There is no concept of a "selected session", clients have an attached session but outside tmux when you don't specify a session the choice of which to use is made separately each time. See here: https://github.com/tmux/tmux/wiki/Advanced-Use#the-default-target
But you shouldn't need it. You are already using -t to specify the window, use it to specify the session as well:
tmux send-keys -t "$SESSION:8021" 'quit' C-m
You don't need select-window either unless you later plan to attach, and then one select-window at the end would do. See https://github.com/tmux/tmux/wiki/Advanced-Use#command-targets for a description of targets.
You may also find the has-session command useful instead of using grep, or the -F flag to list-sessions.
I got the below output but I want to know what does ps auwx does ?
root 2257 0.0 0.0 159532 1628 ? Ss 06:07 0:00 nginx: master process /usr/sbin/nginx -g daemon on
; master_process on;
www-data 2258 0.0 0.1 159864 3380 ? S 06:07 0:00 nginx: worker process
root 2280 0.0 0.0 12780 952 pts/0 S+ 06:08 0:00 grep nginx
As with all things Linux/Unix the man pages are your friend: man ps, man grep
auwx are bsd style parameters (note the lack of an -) and the manual states that these letters represent the following options:
a lift 'only yourself' restriction -> list all processes with a terminal.
u 'user format' -> provides additional information columns.
w wide output -> for when you have a screen wide enough to show all info.
x lift 'must have terminal' restriction -> a+x == list everything.
The output is then piped through to grep which then filters out the line and displays any lines with nginx in it.
We have a shared hosting server, following is what is returned by ps aux | egrep '(apache|httpd)':
nobody 2665023 0.0 0.3 1969096 89628 ? Sl 10:09 0:02 /usr/sbin/httpd -k start
nobody 2665024 0.0 0.1 1968928 41304 ? Sl 10:09 0:05 /usr/sbin/httpd -k start
nobody 2665025 0.0 0.4 1969432 100008 ? Sl 10:09 0:08 /usr/sbin/httpd -k start
nobody 2665971 0.0 0.4 1969432 100880 ? Sl 10:09 0:08 /usr/sbin/httpd -k start
nobody 2665972 0.0 0.4 1969096 110268 ? Sl 10:09 0:18 /usr/sbin/httpd -k start
nobody 2665973 0.0 0.4 1969768 105648 ? Sl 10:09 0:12 /usr/sbin/httpd -k start
A client has a wordpress website with the user myuser.
When an image is uploaded, its owner is nobody:nobody , and cannot be directly accessed from the browser until I execute chown -R myuser:nobody /uploads.|
The problem here is that I cannot execute apache as myuser:nobody since there are other clients on this server (myuser1, myuser2...etc).
How can I possibly solve this?
(I only have general knowledge about permissions, so forgive my ignorance).
Thank you
Brother you have to login as root to the vps server first. Then have to give ownership to each client user like this chown -R /home/client/wp-content/upload.
After that apply su as each client and put recursive permission on files 644 and 775 on directories.
find /home/client/wp-content/upload -type d -exec chmod u=rwx,go=rx {} ;
find /home/client/wp-content/upload -type f -exec chmod u=rw,go=r {} ;
Then you can able to upload images using wordpress media library. Each site also shows the images also.
I created a new session of tmux, intending to use the -s flag to name it, but confused the command with -S which specifies a socket. I know the session is alive, because the processes I started in it are still running. But when I try to list running sessions it does not appear. Where is my session and how do I recover it?
In tmux option -S means socket path (from man tmux):
-S socket-path
Specify a full alternative path to the server socket. If -S is specified, the default
socket directory is not used and any -L flag is ignored.
So you have to find out the parent directory where tmux was run with
-S option and pass this option to tmux to point it to the
alternative socket path. You could for example find PID of the
tmux process:
$ ps aux | grep '[t]mux'
ja 15121 0.0 0.0 20252 2236 pts/6 S+ 00:44 0:00 tmux -S new
And then check this process cwd in /proc like this:
$ ls -l /proc/15121/cwd
lrwxrwxrwx 1 ja users 0 Aug 19 00:52 /proc/15121/cwd -> /home/ja
And then to refer to this tmux session:
$ tmux -S /home/ja/new ls
0: 1 windows (created Sat Aug 19 00:44:46 2017) [212x65] (attached)
I'm using byobu with a tmux backend in Ubuntu 14.04. The standard methods for selecting/viewing sessions such as byobu-select-session and tmux ls do not find the session.
I created a session via incorrect syntax byobu -S wiki and later detached. (I should have done byobu new -s wiki)
The session still exists, according to
$ ps aux | grep byobu
gert 4032 0.1 0.0 29988 8912 ? Ss Jun13 1:46 tmux -f /usr/share/byobu/profiles/tmuxrc -S wiki
I can also see a reference to the session in /tmp
$ ls /tmp/tmux-1001/ -l
total 0
srwxrwx--- 1 gert gert 0 May 30 17:06 default=
srw-rw---- 1 gert gert 0 Jun 14 15:07 wiki=
Try
byobu -S wiki ls
to see if the tmux session is still there. It probably is given your ps output, and will be listed as session 1. Then try
byobu -S wiki attach-session -t 1
Maybe specify the full path to where you can see the "wiki" unix socket that was created when you did byobu -S wiki, which will be in whatever directory you executed that command in originally. Other behavior may occur if byobu or tmux was customized, but basically after you specify byobu -S <path-to-put-socket|path-to-existing-socket-including-socket-name> everything following is going to get passed to tmux. tmux just needs byobu to tell it where to look for its sockets, otherwise it will look in TMPDIR or something by default.
Hope this helps. This is my first ever stackoverflow question that (1) wasn't already answered many different ways, and (2) I knew a possible answer or at least a pointer in the right direction. :)