What does ps auwx | grep nginx means? - unix

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.

Related

How to upload files as certain user:nobody if apache is running as nobody:nobody?

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.

Accidentally used -S when creating my tmux session instead of -s, where is my session?

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)

ps aux | grep between two similar processes

I have written a script, which checks for process, if its running or not. If not then it starts the process.
Lets say I have few processes running like this :
root 5780 0.0 2.2 3168184 85828 ? Sl 09:02 0:15 /usr/bin/java -jar /home/vtermina/private/crons/jar/consumer-1.0.jar promotionalSecond
root 5780 0.0 2.2 3168184 85828 ? Sl 09:02 0:15 /usr/bin/java -jar /home/vtermina/private/crons/jar/consumer-1.0.jar promotionalSecond backup
root 8989 0.0 1.4 2966364 57540 ? Sl 09:04 0:07 /usr/bin/java -jar /home/vtermina/private/crons/jar/update-report-1.0.jar Rb1 backup
So I use following command to check if a process is runnig or not :
ps uax|grep -w "consumer-1.0.jar promotionalSecond" |grep -v grep|wc -l
This command returns me one, if it finds a process running.
It was working fine till recently, when I started using some backup consumers also.
Now if a backup consumer is running,this command returns 1,even if consumer is not running,
How can I grep for exact words in ps aux.
So that my command gives correct result.
Doing some research , I got the answer. Using "$" in search-term, does,what is required. $ tells that the search term ends there.
Like, if I want to check only promotionalSecond and not backup, following command works perfectly.
ps uax|grep -w "consumer-1.0.jar promotionalSecond$" |grep -v grep|wc -l

How to sudo from exec function using nginx, php-fpm, and Arch Linux

I can log in as any user and sudo whoami without password and get "root". When i try this with php -r 'echo exec("sudo whoami");' it works regardless of what user i am. But when i run this through the webserver (nginx) i get nothing. What gives?
ps xau | grep php
root 207 0.0 2.6 19876 4992 ? Ss 23:16 0:00 php-fpm: master process (/etc/php/php-fpm.conf)
http 228 0.0 1.6 19876 3152 ? S 23:16 0:00 php-fpm: pool www
http 229 0.0 1.6 19876 3144 ? S 23:16 0:00 php-fpm: pool www
root 326 0.0 0.3 2504 692 pts/0 S+ 23:59 0:00 grep php
I appended 2>&1 to my command to see errors and it said "sudo: command not found".
I then added putenv('PATH=' . getenv('PATH') . ':/usr/sbin'); to my php script and it worked.

How can I reattach to tmux process

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

Resources