get string on command ps -edf | grep -i mongod

Hello,

How to get the version 3.2.6-ent through shell command :
 

mongod    2530     1  3 Jan23 ?        23:08:29 /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.2.6-ent/bin/mongod -f /var/lib/mongodb/automation-mongod.conf


Thank you

Regards
bibi92Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nociSoftware EngineerCommented:
This will get it....

ps -edf | grep -i mongod | sed -e 's/  */ /g' | cut -d' ' -f 8 | cut -d'/' -f 5  | cut -d'-' -f 4,5

Open in new window


sed with reduce all multiple spaces to one space.
then cut (space) will get the program part,
then cut (/) will get the directory part and
then cut (-) get the last elements
tel2Commented:
That seems to work, noci

But what would be wrong with reducing your one-liner to this?:
ps -edf | grep mongod | cut -d/ -f5 | cut -d- -f4,5

Open in new window

skullnobrainsCommented:
ps -edf | sed -ne  's:.*mongodb-[ ^-][ ^-]*-\([ ^/-][ ^/-]*\).*:\1:p'

or the more efficient

pgrep mongodb ...
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

tel2Commented:
Hi skullnobrains,

I've just tried this solution of yours:
    ps -edf | sed -ne  's:.*mongodb-[ ^-][ ^-]*-\([ ^/-][ ^/-]*\).*:\1:p'
I get no output from it.  Check this out:

$ cat ps-edf.txt
mongod    2530     1  3 Jan23 ?        23:08:29 /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.2.6-ent/bin/mongod -f /var/lib/mongodb/automation-mongod.conf
$ sed -ne 's:.*mongodb-[ ^-][ ^-]*-\([ ^/-][ ^/-]*\).*:\1:p' ps-edf.txt
$
Does it work for you?  If so, please demonstrate.

And please expand on what you mean by this:
    pgrep mongodb ...
particularly the "..." part, which is a bit (or even a byte) ambiguous.
nociSoftware EngineerCommented:
The sed statement reduces possibly multuple space to one so it is  deterministic to split in columns correctly.
Then split  out the program name using the spaces
then split out the directory

So a more top/down splitting.    think about using a username with a - in it.

In this case it will work, until you change to a date formatting that includes a /... (that might also throw off spaces counting btw)...
tel2Commented:
Hi noci,

When you say:
   "In this case it will work..."
about the sed statement, did you try it?  is it working for you?  As you can see by my last post, it ain't working for me.
skullnobrainsCommented:
gladly

$ echo 'mongod    2530     1  3 Jan23 ?        23:08:29 /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.2.6-ent/bin/mongod -f /var/lib/mongodb/automation-mongod.conf' > /tmp/edf
$ cat /tmp/edf | sed -ne 's:.*mongodb-[ ^-][ ^-]*-\([ ^/-][ ^/-]*\).*:\1:p'
$ cat /tmp/edf | sed -ne 's:.*mongodb-[^-][^-]*-\([^/-][^/-]*\).*:\1:p'
x86_64

Open in new window


my second attempt works because i removed the extra spaces which got somehow added before each "^" character

__


"pgrep mongodb" would be a replacement for "ps -edf" that only outputs the mongodb process.
you may need to adjust the command.
it does not make much of a difference but will be a little more efficient if you have lots of process running
nociSoftware EngineerCommented:
ps -edf | grep -i mongod      == replaced with echo ........


$ echo 'mongod    2530     1  3 Jan23 ?        23:08:29 /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.2.6-ent/bin/mongod -f /var/lib/mongodb/automation-mongod.conf'| sed -e 's/  */ /g' | cut -d' ' -f 8 | cut -d'/' -f 5  | cut -d'-' -f 4,5
3.2.6-ent
$ 

Open in new window

So it works... please check space count s/  */ /g     reads: es slash space space star slash space slash gee  
space space star   -     one space to anchor, and zero or more spaces to replace...,    ==> every string of 1 or more space is repalce by one space.
When typeing one space it will not work, also with three spaces it will not work.
A better approach would be space space + (  +)  where 2 or more spaces will be replaced with a single space, leaving all single spaces alone.
alas not all sed implementation allow for a + in the the Regular Expression.
tel2Commented:
Hi skullnobrains,
$ cat /tmp/edf | sed -ne 's:.*mongodb-[^-][^-]*-\([^/-][^/-]*\).*:\1:p'
x86_64
my second attempt works because i removed the extra spaces which got somehow added before each "^" character

I don't think your second attempt works, because bibi92 asked for "3.2.6-ent", not "x86_64".
Looking forward to your 3rd attempt.  8)

Hi noci,
I'm still waiting for your answer to my question "what would be wrong with reducing your one-liner to this?:"
ps -edf | grep '^mongod ' | cut -d/ -f5 | cut -d- -f4,5

Open in new window

(Note: I've now added '^' above to ensure the match is at the start of the line only, (and presumably speed up the matching process minutely), and quotes with a space after to prevent matches with (admittedly unlikely) usernames like 'mongod2'.)
skullnobrainsCommented:
@tel2

lol, here is the third

$ cat /tmp/edf | sed -ne 's:.*mongodb-[^-][^-]*-[^-][^-]*-\([^/-][^/-]*\).*:\1:p'
3.2.6

Open in new window


anyway, that's just for the sake of oversimplifying. i marked @noci's initial answer as the solution
tel2Commented:
As much as I hate to sound like a broken record, skullnobrains...
I don't think your third attempt works, because bibi92 asked for "3.2.6-ent", not "3.2.6".  But you're getting closer.
Looking forward to your 4th attempt.  8)
skullnobrainsCommented:
lol, no, i see no point in the game. i merely wanted to demonstrate it is feasible with a single sed. i did my last attempt around 4AM... and i'm prtty sure the author does no really care and every single other contributor in this thread can do the exercise easily... s:.*mongodb-[^-][^-]*-[^-][^-]*-\([^/][^/]*\).*:\1:p
tel2Commented:
Well done, skullnobrains.
It seems you do your best work when you see no point in it.   8)
skullnobrainsCommented:
hopefully, my job is often pointless ( ^ω^)
bibi92Author Commented:
Hello,

Exactly, sorry for the delay, I search to get 3.2.6-ent.

Thank you

Best regards
bibi92Author Commented:
Hello

ps -edf | grep '^mongod ' | cut -d/ -f5 | cut -d- -f4,5
agent -f
3.2.6-ent
agent-6.1.2.402

I need to get only 3.2.6-ent

Thank you

Best regards
tel2Commented:
Hi bibi92,

Please provide the output of "ps -edf" which returns those results from the command you ran.  Then we can find out what's going wrong and try to fix it.
bibi92Author Commented:
Hello

ps -edf | grep '^mongod ' | cut -d/ -f5 | cut -d- -f4,5 returns :

 agent -f
 3.2.6-ent
 agent-6.1.2.402

 I need to get only 3.2.6-ent

 Thank you

 Best regards
tel2Commented:
Hi bibi92,

You already showed us what
    ps -edf | grep '^mongod ' | cut -d/ -f5 | cut -d- -f4,5
returns, but I did not ask for that.  I want the output from this:
    ps -edf
Then we can find out what's going wrong and try to fix it.
bibi92Author Commented:
Hello,

ps -edf return :
[root@TESTMG etc]# ps -edf
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Mar16 ?        00:00:07 /sbin/init
root         2     0  0 Mar16 ?        00:00:00 [kthreadd]
root         3     2  0 Mar16 ?        00:00:08 [migration/0]
root         4     2  0 Mar16 ?        00:00:15 [ksoftirqd/0]
root         5     2  0 Mar16 ?        00:00:00 [stopper/0]
root         6     2  0 Mar16 ?        00:00:00 [watchdog/0]
root         7     2  0 Mar16 ?        00:00:08 [migration/1]
root         8     2  0 Mar16 ?        00:00:00 [stopper/1]
root         9     2  0 Mar16 ?        00:00:14 [ksoftirqd/1]
root        10     2  0 Mar16 ?        00:00:00 [watchdog/1]
root        11     2  0 Mar16 ?        00:00:08 [migration/2]
root        12     2  0 Mar16 ?        00:00:00 [stopper/2]
root        13     2  0 Mar16 ?        00:00:14 [ksoftirqd/2]
root        14     2  0 Mar16 ?        00:00:00 [watchdog/2]
root        15     2  0 Mar16 ?        00:00:08 [migration/3]
root        16     2  0 Mar16 ?        00:00:00 [stopper/3]
root        17     2  0 Mar16 ?        00:00:17 [ksoftirqd/3]
root        18     2  0 Mar16 ?        00:00:00 [watchdog/3]
root        19     2  0 Mar16 ?        00:00:18 [events/0]
root        20     2  0 Mar16 ?        00:00:18 [events/1]
root        21     2  0 Mar16 ?        00:00:22 [events/2]
root        22     2  0 Mar16 ?        00:00:35 [events/3]
root        23     2  0 Mar16 ?        00:00:00 [events/0]
root        24     2  0 Mar16 ?        00:00:00 [events/1]
root        25     2  0 Mar16 ?        00:00:00 [events/2]
root        26     2  0 Mar16 ?        00:00:00 [events/3]
root        27     2  0 Mar16 ?        00:00:00 [events_long/0]
root        28     2  0 Mar16 ?        00:00:00 [events_long/1]
root        29     2  0 Mar16 ?        00:00:00 [events_long/2]
root        30     2  0 Mar16 ?        00:00:00 [events_long/3]
root        31     2  0 Mar16 ?        00:00:00 [events_power_ef]
root        32     2  0 Mar16 ?        00:00:00 [events_power_ef]
root        33     2  0 Mar16 ?        00:00:00 [events_power_ef]
root        34     2  0 Mar16 ?        00:00:00 [events_power_ef]
root        35     2  0 Mar16 ?        00:00:00 [cgroup]
root        36     2  0 Mar16 ?        00:00:00 [khelper]
root        37     2  0 Mar16 ?        00:00:00 [netns]
root        38     2  0 Mar16 ?        00:00:00 [async/mgr]
root        39     2  0 Mar16 ?        00:00:00 [pm]
root        40     2  0 Mar16 ?        00:00:01 [sync_supers]
root        41     2  0 Mar16 ?        00:00:00 [bdi-default]
root        42     2  0 Mar16 ?        00:00:00 [kintegrityd/0]
root        43     2  0 Mar16 ?        00:00:00 [kintegrityd/1]
root        44     2  0 Mar16 ?        00:00:00 [kintegrityd/2]
root        45     2  0 Mar16 ?        00:00:00 [kintegrityd/3]
root        46     2  0 Mar16 ?        00:00:00 [kblockd/0]
root        47     2  0 Mar16 ?        00:00:00 [kblockd/1]
root        48     2  0 Mar16 ?        00:00:00 [kblockd/2]
root        49     2  0 Mar16 ?        00:00:00 [kblockd/3]
root        50     2  0 Mar16 ?        00:00:00 [kacpid]
root        51     2  0 Mar16 ?        00:00:00 [kacpi_notify]
root        52     2  0 Mar16 ?        00:00:00 [kacpi_hotplug]
root        53     2  0 Mar16 ?        00:00:00 [ata_aux]
root        54     2  0 Mar16 ?        00:00:00 [ata_sff/0]
root        55     2  0 Mar16 ?        00:00:00 [ata_sff/1]
root        56     2  0 Mar16 ?        00:00:00 [ata_sff/2]
root        57     2  0 Mar16 ?        00:00:00 [ata_sff/3]
root        58     2  0 Mar16 ?        00:00:00 [ksuspend_usbd]
root        59     2  0 Mar16 ?        00:00:00 [khubd]
root        60     2  0 Mar16 ?        00:00:00 [kseriod]
root        61     2  0 Mar16 ?        00:00:00 [md/0]
root        62     2  0 Mar16 ?        00:00:00 [md/1]
root        63     2  0 Mar16 ?        00:00:00 [md/2]
root        64     2  0 Mar16 ?        00:00:00 [md/3]
root        65     2  0 Mar16 ?        00:00:00 [md_misc/0]
root        66     2  0 Mar16 ?        00:00:00 [md_misc/1]
root        67     2  0 Mar16 ?        00:00:00 [md_misc/2]
root        68     2  0 Mar16 ?        00:00:00 [md_misc/3]
root        69     2  0 Mar16 ?        00:00:00 [linkwatch]
root        72     2  0 Mar16 ?        00:00:00 [khungtaskd]
root        73     2  0 Mar16 ?        00:00:00 [lru-add-drain/0]
root        74     2  0 Mar16 ?        00:00:00 [lru-add-drain/1]
root        75     2  0 Mar16 ?        00:00:00 [lru-add-drain/2]
root        76     2  0 Mar16 ?        00:00:00 [lru-add-drain/3]
root        77     2  0 Mar16 ?        00:00:01 [kswapd0]
root        78     2  0 Mar16 ?        00:00:00 [ksmd]
root        80     2  0 Mar16 ?        00:00:00 [aio/0]
root        81     2  0 Mar16 ?        00:00:00 [aio/1]
root        82     2  0 Mar16 ?        00:00:00 [aio/2]
root        83     2  0 Mar16 ?        00:00:00 [aio/3]
root        84     2  0 Mar16 ?        00:00:00 [crypto/0]
root        85     2  0 Mar16 ?        00:00:00 [crypto/1]
root        86     2  0 Mar16 ?        00:00:00 [crypto/2]
root        87     2  0 Mar16 ?        00:00:00 [crypto/3]
root        94     2  0 Mar16 ?        00:00:00 [kthrotld/0]
root        95     2  0 Mar16 ?        00:00:00 [kthrotld/1]
root        96     2  0 Mar16 ?        00:00:00 [kthrotld/2]
root        97     2  0 Mar16 ?        00:00:00 [kthrotld/3]
root        98     2  0 Mar16 ?        00:00:00 [pciehpd]
root       100     2  0 Mar16 ?        00:00:00 [kpsmoused]
root       101     2  0 Mar16 ?        00:00:00 [usbhid_resumer]
root       102     2  0 Mar16 ?        00:00:00 [deferwq]
root       135     2  0 Mar16 ?        00:00:00 [kdmremove]
root       136     2  0 Mar16 ?        00:00:00 [kstriped]
root       165     2  0 Mar16 ?        00:00:00 [ttm_swap]
root       385     2  0 Mar16 ?        00:00:00 [scsi_eh_0]
root       386     2  0 Mar16 ?        00:00:00 [scsi_eh_1]
root       392     2  0 Mar16 ?        00:00:07 [mpt_poll_0]
root       393     2  0 Mar16 ?        00:00:00 [mpt/0]
root       394     2  0 Mar16 ?        00:00:00 [scsi_eh_2]
root       486     2  0 Mar16 ?        00:00:00 [dm_bufio_cache]
root       487     2  0 Mar16 ?        00:00:00 [kdmflush]
root       488     2  0 Mar16 ?        00:00:00 [kdmflush]
root       489     2  0 Mar16 ?        00:00:00 [kdmflush]
root       491     2  0 Mar16 ?        00:00:00 [kdmflush]
root       492     2  0 Mar16 ?        00:00:00 [ksnaphd]
root       494     2  0 Mar16 ?        00:00:00 [kcopyd]
root       519     2  0 Mar16 ?        00:00:00 [jbd2/dm-1-8]
root       520     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root       620     1  0 Mar16 ?        00:00:00 /sbin/udevd -d
root       845     2  0 Mar16 ?        00:00:06 [vmmemctl]
root      1070     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1073     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1074     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1077     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1098     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1099     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1101     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1103     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1106     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1107     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1115     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1119     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1125     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1132     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1134     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1136     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1137     2  0 Mar16 ?        00:00:00 [ksnaphd]
root      1139     2  0 Mar16 ?        00:00:00 [kcopyd]
root      1155     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1157     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1160     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1164     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1166     2  0 Mar16 ?        00:00:00 [ksnaphd]
root      1167     2  0 Mar16 ?        00:00:09 [kcopyd]
root      1184     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1188     2  0 Mar16 ?        00:00:00 [kdmflush]
root      1296     2  0 Mar16 ?        00:00:00 [jbd2/sda1-8]
root      1297     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1298     2  0 Mar16 ?        00:00:00 [jbd2/dm-8-8]
root      1299     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1300     2  0 Mar16 ?        00:00:00 [jbd2/dm-9-8]
root      1301     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1302     2  0 Mar16 ?        00:00:00 [jbd2/dm-10-8]
root      1303     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1304     2  0 Mar16 ?        00:00:00 [jbd2/dm-11-8]
root      1305     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1306     2  0 Mar16 ?        00:00:00 [jbd2/dm-12-8]
root      1307     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1308     2  0 Mar16 ?        00:00:00 [jbd2/dm-13-8]
root      1309     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1310     2  0 Mar16 ?        00:00:00 [jbd2/dm-14-8]
root      1311     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1312     2  0 Mar16 ?        00:00:07 [jbd2/dm-15-8]
root      1313     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1314     2  0 Mar16 ?        00:00:00 [jbd2/dm-17-8]
root      1315     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1316     2  0 Mar16 ?        00:00:36 [jbd2/dm-21-8]
root      1317     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1320     2  0 Mar16 ?        00:00:00 [xfs_mru_cache]
root      1321     2  0 Mar16 ?        00:00:01 [xfslogd/0]
root      1322     2  0 Mar16 ?        00:00:01 [xfslogd/1]
root      1323     2  0 Mar16 ?        00:00:01 [xfslogd/2]
root      1324     2  0 Mar16 ?        00:00:01 [xfslogd/3]
root      1325     2  0 Mar16 ?        00:00:00 [xfsdatad/0]
root      1326     2  0 Mar16 ?        00:00:00 [xfsdatad/1]
root      1327     2  0 Mar16 ?        00:00:00 [xfsdatad/2]
root      1328     2  0 Mar16 ?        00:00:00 [xfsdatad/3]
root      1329     2  0 Mar16 ?        00:00:02 [xfsconvertd/0]
root      1330     2  0 Mar16 ?        00:00:01 [xfsconvertd/1]
root      1331     2  0 Mar16 ?        00:00:01 [xfsconvertd/2]
root      1332     2  0 Mar16 ?        00:00:01 [xfsconvertd/3]
root      1333     2  0 Mar16 ?        00:00:00 [xfsalloc/0]
root      1334     2  0 Mar16 ?        00:00:00 [xfsalloc/1]
root      1335     2  0 Mar16 ?        00:00:00 [xfsalloc/2]
root      1336     2  0 Mar16 ?        00:00:00 [xfsalloc/3]
root      1337     2  0 Mar16 ?        00:00:00 [xfseofblocks/0]
root      1338     2  0 Mar16 ?        00:00:00 [xfseofblocks/1]
root      1339     2  0 Mar16 ?        00:00:00 [xfseofblocks/2]
root      1340     2  0 Mar16 ?        00:00:00 [xfseofblocks/3]
root      1341     2  0 Mar16 ?        00:00:00 [xfsbufd/dm-5]
root      1342     2  0 Mar16 ?        00:00:00 [xfs-cil/dm-5]
root      1343     2  0 Mar16 ?        00:00:01 [xfssyncd/dm-5]
root      1344     2  0 Mar16 ?        00:01:48 [xfsaild/dm-5]
root      1345     2  0 Mar16 ?        00:00:07 [xfsbufd/dm-4]
root      1346     2  0 Mar16 ?        00:00:03 [xfs-cil/dm-4]
root      1347     2  0 Mar16 ?        00:00:01 [xfssyncd/dm-4]
root      1348     2  0 Mar16 ?        00:01:55 [xfsaild/dm-4]
root      1349     2  0 Mar16 ?        00:00:00 [jbd2/dm-24-8]
root      1350     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1351     2  0 Mar16 ?        00:00:01 [jbd2/dm-25-8]
root      1352     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1353     2  0 Mar16 ?        00:00:00 [jbd2/dm-6-8]
root      1354     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1355     2  0 Mar16 ?        00:00:00 [jbd2/dm-7-8]
root      1356     2  0 Mar16 ?        00:00:00 [ext4-dio-unwrit]
root      1400     2  0 Mar16 ?        00:00:02 [kauditd]
root      1450     1  0 Mar16 ?        00:00:33 /sbin/dmeventd
root      1587     1  0 Mar16 ?        00:00:00 /usr/lib/vmware-vgauth/VGAuthSer
root      1588     1  0 Mar16 ?        00:05:36 /usr/sbin/vmtoolsd
root      1767     2  0 Mar16 ?        00:00:00 [flush-253:9]
root      1773     2  0 Mar16 ?        00:00:01 [flush-253:15]
root      1775     2  0 Mar16 ?        00:00:05 [flush-253:21]
root      1777     2  0 Mar16 ?        00:00:00 [flush-253:25]
root      1941     1  0 Mar16 ?        00:00:07 auditd
root      1965     1  0 Mar16 ?        00:00:00 /sbin/portreserve
root      1975     1  0 Mar16 ?        00:00:00 /sbin/rsyslogd -i /var/run/syslo
root      1990     1  0 Mar16 ?        00:01:43 irqbalance --pid=/var/run/irqbal
root      2004     1  0 Mar16 ?        00:00:18 /usr/sbin/sssd -f -D
root      2005  2004  0 Mar16 ?        00:00:23 /usr/libexec/sssd/sssd_be --doma
root      2006  2004  0 Mar16 ?        00:00:06 /usr/libexec/sssd/sssd_be --doma
root      2007  2004  0 Mar16 ?        00:00:08 /usr/libexec/sssd/sssd_be --doma
root      2008  2004  0 Mar16 ?        00:00:06 /usr/libexec/sssd/sssd_nss --uid
root      2009  2004  0 Mar16 ?        00:00:03 /usr/libexec/sssd/sssd_pam --uid
root      2010  2004  0 Mar16 ?        00:00:04 /usr/libexec/sssd/sssd_sudo --ui
root      2029     1  0 Mar16 ?        00:00:00 /usr/sbin/sshd
root      2050     1  0 Mar16 ?        00:00:00 /usr/sbin/sshd -f /etc/ssh-scom/
root      7023     2  0 Mar16 ?        00:00:02 [flush-253:5]
root      7024     2  0 Mar16 ?        00:00:01 [flush-253:4]
root      7078     1  0 Mar16 ?        00:00:05 /var/itlm/tlmagent.bin
dbus      7100     1  0 Mar16 ?        00:00:00 dbus-daemon --system
68        7121     1  0 Mar16 ?        00:00:02 hald
root      7122  7121  0 Mar16 ?        00:00:00 hald-runner
root      7154  7122  0 Mar16 ?        00:00:00 hald-addon-input: Listening on /
68        7172  7122  0 Mar16 ?        00:00:08 /usr/libexec/hald-addon-acpi
root      7243     1  0 Mar16 ?        00:00:21 /opt/universal/ubroker/bin/ubrok
ntp       7253     1  0 Mar16 ?        00:00:01 ntpd -u ntp:ntp -p /var/run/ntpd
root      7267  7243  0 Mar16 ?        00:00:15 /opt/universal/uemsrv/bin/uemsrv
root      7336     1  0 Mar16 ?        00:00:05 /usr/libexec/postfix/master
root      7348     1  0 Mar16 ?        00:00:00 /usr/sbin/abrtd
postfix   7350  7336  0 Mar16 ?        00:00:00 qmgr -l -t fifo -u
root      7445     1  0 Mar16 ?        00:00:06 crond
mongod    7481     1  0 Mar16 ?        01:20:53 /opt/mongodb-mms-automation/bin/
root      7539     1  0 Mar16 ?        00:01:17 /usr/bin/perl -wT /usr/sbin/muni
mongod    7651     1  2 Mar16 ?        03:15:06 /var/lib/mongodb-mms-automation/
mongod    7725     1  0 Mar16 ?        00:14:18 /var/lib/mongodb-mms-automation/
root      7768     1  0 Mar16 ?        00:00:00 bin/rscw
root      7805  7768  0 Mar16 ?        00:00:00 bin/rscd
root      7806  7768  0 Mar16 ?        00:00:00 bin/rscd
root      8050     1  0 Mar16 ?        00:00:00 /usr/bin/rhsmcertd
root      8406     1  0 Mar16 ?        00:00:01 /opt/managesoft/libexec/mgsusage
root      8417     1  0 Mar16 ?        00:00:05 /opt/managesoft/libexec/ndtask
netdata   8429     1  0 Mar16 ?        00:58:15 /usr/sbin/netdata -P /var/run/ne
root      8476     1  0 Mar16 tty1     00:00:00 /sbin/mingetty /dev/tty1
root      8478     1  0 Mar16 tty2     00:00:00 /sbin/mingetty /dev/tty2
netdata   8489  8429  0 Mar16 ?        00:02:44 /usr/bin/python /usr/libexec/net
netdata   8490  8429  0 Mar16 ?        00:03:42 /usr/libexec/netdata/plugins.d/g
root      8507   620  0 Mar16 ?        00:00:00 /sbin/udevd -d
root      8509   620  0 Mar16 ?        00:00:00 /sbin/udevd -d
root     34459     1  0 03:34 ?        00:00:25 python /usr/bin/goferd
postfix  36919  7336  0 07:32 ?        00:00:00 pickup -l -t fifo -u
postfix  47502  7336  0 07:51 ?        00:00:00 showq -t unix -u
netdata  48491  8429  1 05:56 ?        00:02:23 /usr/libexec/netdata/plugins.d/a
netdata  51798  8429  0 07:59 ?        00:00:00 bash /usr/libexec/netdata/plugin
root     52560     2  0 08:01 ?        00:00:00 [flush-253:17]
704623   53246 53245  0 08:02 pts/0    00:00:00 -bash
root     53351     2  0 08:02 ?        00:00:00 [flush-253:8]
root     53359 53246  0 08:02 pts/0    00:00:00 sudo su root
root     53362 53359  0 08:02 pts/0    00:00:00 su root
root     53363 53362  0 08:02 pts/0    00:00:00 bash
root     56052 53363  0 08:07 pts/0    00:00:00 ps -edf

Best regards
tel2Commented:
Hi bibi92,

Your original post gave us this data to extract "3.2.6-ent" from:

mongod    2530     1  3 Jan23 ?        23:08:29 /var/lib/mongodb-mms-automation/mongodb-linux-x86_64-3.2.6-ent/bin/mongod -f /var/lib/mongodb/automation-mongod.conf

The only lines starting with "mongod" in your last post are these:

mongod    7481     1  0 Mar16 ?        01:20:53 /opt/mongodb-mms-automation/bin/
mongod    7651     1  2 Mar16 ?        03:15:06 /var/lib/mongodb-mms-automation/
mongod    7725     1  0 Mar16 ?        00:14:18 /var/lib/mongodb-mms-automation/

How are we supposed to find "3.2.6-ent" in those?
nociSoftware EngineerCommented:
Seems a non wrapped window cutting off the beyond the right edge..., so that info is lost...
Now why doesn't this work:

ps -edf | grep -i mongod | sed -e 's/  */ /g' | cut -d' ' -f 8 | cut -d'/' -f 5  | cut -d'-' -f 4,5

Open in new window

bibi92Author Commented:
Hello,

$ ps -edf | grep -i mongod | sed -e 's/  */ /g' |  cut -d' ' -f 8 | cut -d'/' -f 5  | cut -d'-' -f 4,5
agent
3.2.6-ent
agent-6.1.2.402
grep

Only 3.2.6-ent must be returned.

Thank you

Best regards
nociSoftware EngineerCommented:
ps -edf | grep -i mongod | sed -e 's/  */ /g' | cut -d' ' -f 8 | cut -d'/' -f 5  | cut -d'-' -f 4,5 | grep -v grep | grep -v agent

Open in new window


Try the above, then all the unwanted records are reoved.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tel2Commented:
I'm still waiting for your answer to the question at the bottom of my last post, bibi92.
Please provide data which contains the stuff you're wanting us to extract for you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.