Hi,
I need a script that needs to detect the Operating System and based upon wheter it is Linux, Solaris x86, Sparc, Itanium etc it should populate "ps" command with detailed output accordingly
for example:
ps -xef | grep java -> Itanium
ps -auxwww | greap java -> Solaris
Try
uname
command to know about the version.
I understand uname will do the job but I am not sure what and how to grep from the uname's output and i am not sure about the various ps command formats for various OSs.
Can you please help me with a short script ?
You can try something like this
#!/bin/sh
v1=$(uname)
if [[ "$v1" = Linux ]];then
ps -ef | grep java
fi
else
echo "wrong option"
fi
Similarly by using
if statement
in loop you can try for other.
1 Like
vikram_tanwar12:
You can try something like this
#!/bin/sh
uname
if [[ uname -eq Linux ]];then
ps -ef | grep java
fi
Similarly by using
if statement
in loop you can try for other.
SunOS
HP-UX
Can you help list any more Operating Systems ?
vikram_tanwar12:
AIX and FreeBSD
Can you give me relevant ps statements for the mentioned OS [AIX and FreeBSD] ?
Check the below links for more information.
pSeries and AIX Information Center
ps
drl
February 19, 2013, 11:57am
9
Hi.
See also the 1500-line GNU shell script config.guess at http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
Best wishes ... cheers, drl
uname
is sufficient for shell commands like df and ps.
For inventory etc. you want uname -sm
The case statement can be used like this:
#!/bin/sh
os=`uname -s`
model=`uname -m`
case "$os $model" in
"SunOS sun4u") echo "Solaris on SPARC";;
"SunOS i86pc") echo "Solaris on x86";;
"HP-UX 9000/800") echo "HP-UX on PA-RISC";;
"HP-UX ia64") echo "HP-UX on Itanium";;
"Linux x86_64") echo "Linux on x86, 64bit";;
"Linux i686") echo "Linux on x86, 32bit";;
AIX*) echo "AIX on $model";;
FreeBSD*) echo "FreeBSD on $model";;
*) echo "$os on $model";;
esac
ps -ef
works on all operating systems but BSD. BSD needs ps auxw
. Linux takes both.
For cross-reference, book-mark this: Rosetta Stone for Unix