How can we find the system service name of oracle db? - linux

when I run ps -ef it is showing something like this
oracle 42547 1 0 Mar14 ? 00:00:35 asm_pmon_+ASM
Help me to find exact service name for oracle Database.

ps -ef | grep pmon
will show you all the processes monitor processes running in the server.
In your case, it shows asm_pmon_+ASM is the name of the process, which means,
+ASM is one of your instances running.
to extract +ASM only from the text, use:
ps -ef | grep "[p]mon" | awk -F "_" '{ print $NF }'.
Another option is to use pgrep pmon instead of ps -ef | grep ..
It is pretty straightforward when you are connected to the database instead.
select sys_context('USERENV','SERVICE_NAME') from dual;

Related

Linux ps aux with grep check for specific PHP process ID

I'm trying to figure out whether a PHP process is running or not using the ps aux command and passing grep to it, for instance:
I need it to return and tell me whether a process ID on php is running or not but whenever I try the following I always seem to get a result where the result is appending 1234 at the end, what am I missing?
ps aux | grep 'php|1234'
Suggesting pgrep command instead of ps aux
pgrep -af "php"
The reason your get always one line:
php process is not matched with grep 'php|123123123'
ps aux list the grep command you submitted and the grep command match itself
maybe you meant grep -E 'php|123123123' to match php or 123123123
The solution I've come across thanks to a user above is to do:
ps aux | grep '123456' | grep 'grep' -v
Where 123456 would be the process ID

Shell : How to get pid given apart of its name string

I've this running java process:
testuser 37126 1 0 2018 ? 01:56:24 java -jar backend76465465.jar -XX:-OmitStackTraceInFastThrow --spring.profiles.active=server
I want to dynamically get its pid based on :
a part of its name: "backend"
(which is the fix part "backend") ,
the other part : 76465465 would always change
i ve tried this :
ps -eaf | awk '$NF~"backend" {print $2}'
and this :
ps -eaf | grep java | awk '$NF~"backend" {print $2}'
but it still give me empty results .
Suggestions ?
Try pgrep , it will return the pid of the matched process :
pgrep -f backend
Have you tried to use ps aux | grep backend?

How can use one ssh for two commands to save 2 different files

How can use one ssh for two commands to save 2 different files. Like one command is ps -ef | grep Consumer | cut -f6 -d' ' and save this output in file.log, second command is ps -ef | grep Test | cut -f7 -d' ' and save output in test.log
Only ps -ef needs to be run on the remote system. Parsing the output can happen at local system.
& It's easier with awk. Needs just single ssh session & ps -ef command snapshot:
ssh user#host ps -ef | awk -F' ' '/Consumer/{print $6 > "file.log"}; /Test/{print $7 > "test.log"}'
grep+cut can happen within awk - '/pattern/{print $n}'
File redirection can also happen easily with awk. Check the syntax in above answer.
I would rather prefer to do parsing on remote system only as ps -ef gives a big output and if we don't parse and cut it over there then entire output is transferred from remote system to local system over network. It can take more time if output size increases. And we don't even need entire output on local system too so it is better parse it on remote system only.
ssh user#host ps -ef | grep Consumer | cut -f6 -d' ' > file.log; ps -ef | grep Test | cut -f7 -d' ' > test.log

Get pid of last started instance of a certain process

I have several instances of a certain process running and I want to determine the process id of the one that has been started last.
So far I came to this code:
ps -aef | grep myProcess | grep -v grep | awk -F" " '{print $2}' |
while read line; do
echo $line
done
This gets me all process ids of myProcess. Somehow I need to compare now the running times of this pids and find out the one with the smallest running time. But I don't know how to do that...
An easier way would be to use pgrep with its -n, --newest switch.
Select only the newest (most recently started) of the matching
processes.
Alternatively, if you don't want to use pgrep, you can use ps and sort by start time:
ps -ef kbsdstart
Use pgrep. It has a -n (newest) option for that. So just try
pgrep -n myProcess

Linux command get tomcat process id by name

Linux command line:
When i execute the following command ps -ef |grep tomcat it shows me the following process
abcapp 28119 1 0 12:53 ? 00:00:19 /usr/java/jdk1.6.0_10//bin/java -Xmx256m -Dabc.log.file=/home/app/apps/rum/logs/dev.log -Dabc.config=dev -Dlog4j.configuration=file:///home/abcapp/env/abc_env/abc_env-1.2/config/log4j-webapp.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/home/abcapp/env/tomcat/tomcat-5.5-26-rum/conf/logging.properties -Djava.endorsed.dirs=/home/abcapp/env/tomcat/tomcat-5.5-26-rum/common/endorsed -classpath :/home/abcapp/env/tomcat/tomcat-5.5-26-rum/bin/bootstrap.jar:/home/abcapp/env/tomcat/tomcat-5.5-26-rum/bin/commons-logging-api.jar -Dcatalina.base=/home/abcapp/env/tomcat/tomcat-5.5-26-rum -Dcatalina.home=/home/abcapp/env/tomcat/tomcat-5.5-26-rum -Djava.io.tmpdir=/home/abcapp/env/tomcat/tomcat-5.5-26-rum/temp org.apache.catalina.startup.Bootstrap start
but when i issue following command it shows nothing
pgrep tomcat-5.5-26-rum OR pgrep "*-rum"
can some body help me how can i get tomcat process id by its name regex for "*-rum"
Thanks in advance.
pgrep only search for the process name without the full path (in your case only java) and without arguments.
Since tomcat-5.5-26-rum is part of the latter, i'd search the pid with
ps -ef | grep tomcat-5.5-26-rum | grep java | awk ' { print $2 } '
The double grep is useful to discard the grep pids itself
Just add following line at the start of catalina.sh file
CATALINA_PID="$CATALINA_BASE"/logs/tomcat.pid
OR
CATALINA_PID=/tmp/tomcat.pid
And bounce tomcat. This will create a tomcat.pid file in the given path and put the Tomcat process pid in it.
This worked for me:
This will give the process id of current running tomcat
echo ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'

Resources