Selective Output for my Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Selective Output for my Script
# 1  
Old 06-19-2012
Selective Output for my Script

Hey everyone, I have a very simple BASH shell script that simply checks what processes I have running on a few different nodes, which are preknown. Currently, my script spews out all the processes on all the nodes, but I'm really only interested in one process per node. The processes I am interested are the only .exe processes on the nodes. Is there a way I could edit my script so that I only see those processes? Here's a sample of my current code:
Code:
echo "n111"
ssh n111 ps -u scn
echo "n109"
ssh n109 ps -u scn
.....

And the output looks something like,
Code:
n111
PID     TTY        Time      CMD
8529    ?          00:00:00   g09
8530    ?          00:12:39   1703.exe
8548    ?          00:00:00   sshd
.....

The bolded process is the one I would like to isolate and display.
Any help would be greatly appreciated.

Last edited by Stuart Ness; 06-19-2012 at 10:57 AM.. Reason: Forgot to list scripting language
# 2  
Old 06-19-2012
Code:
ssh n111 ps -u scn | grep exe

# 3  
Old 06-19-2012
Code:
ssh n111 -n "ps -u scn | grep [e]xe"

# 4  
Old 06-19-2012
Depending on how the remote system behave, you might need to exclude "grep" itself from the list.

Code:
ssh n111 ps -u scn | grep "exe" | grep -v "grep"

Edit: ctsgnb's solution is better.
# 5  
Old 06-19-2012
In case all you need is a pid:
Code:
pgrep -u scn '\.exe$'

Regards,
Alister
# 6  
Old 06-19-2012
Nice, thanks everybody!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Backup script with selective file types only

i am looking for a backup script to be run in ssh which can move all *.php files only to a archive Eg. a folder has 5 sub folders with different file types, which can be mix of PDF, jpeg, gif etc etc. but the archive generated should only include the *.php files without breaking the directory... (3 Replies)
Discussion started by: netatma
3 Replies

2. Shell Programming and Scripting

Redirect script output to a file and mail the output

Hi Guys, I want to redirect the output of 3 scripts to a file and then mail the output of those three scripts. I used below but it is not working: OFILE=/home/home1/report1 echo "report1 details" > $OFILE =/home/home1/1.sh > $OFILE echo... (7 Replies)
Discussion started by: Vivekit82
7 Replies

3. Shell Programming and Scripting

How to output selective delimited data to a new file?

I have the following file which at times can be quite large so can be difficult to read, I need a script that just extracts particular delimited data and outputs to alternate file $cat fix1.log FIX4.4|0=12|55=LIT.L|48=123456|32=5|52=20111107-10:52:22.128|38=100|10=200| ... (6 Replies)
Discussion started by: Buddyluv
6 Replies

4. UNIX for Dummies Questions & Answers

Selective replace

i have a large sequence of format sat_1_g3_g_0_8540 . A 1 15501 . . . ID=sat_1_g3_g_0_8540;parentName=sat_1_g3_g_0_8540;Al=sat_1_g2_g_0_8540; sat_1_g3_g_2_8510 . C 1 25501 . . . ... (11 Replies)
Discussion started by: siya@
11 Replies

5. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

6. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

7. UNIX for Dummies Questions & Answers

Help with selective ls

Hi all :wall: Can anyone advise how do I use ls to do a selective amd sorted listing of file that I want to have as below? Am looking for files that are named as log_<nnnn>.txt, where <nnnn> are numeric, i.e. I want to have a listing sorted from the newest to the oldest of files that... (7 Replies)
Discussion started by: newbie_01
7 Replies

8. Shell Programming and Scripting

selective printing

hi all from below text "abcd,SYS_12345,xyz,PQR, ," I want to print only "abcd,SYS,xyz,PQR, ," i.e. taking only first three 3 chars from 2 string of comma separated file thanks (4 Replies)
Discussion started by: JoeColeEPL9
4 Replies

9. Red Hat

Cron task output is 0, script output is OK

I have the following cron task set to run every 15 minutes to ascertain how many users are in the system and append the result to the log. /home/pronto/cus/whoisinc >> /home/pronto/cus/whoisin.log This is the whoisinc script date +"%d-%m-%Y,%k:%M,Pronto Users,`prowho -s | grep -v... (1 Reply)
Discussion started by: scottm
1 Replies

10. Shell Programming and Scripting

sed/awk script selective insert between lines

Hi I have a file in the foll. format *RECORD* *FIELD NO* ....... ....... *FIELD TX* Data *FIELD AV* Data *FIELD RF* *RECORD* *FIELD NO* ....... ....... *FIELD TX* Data *FIELD RF* (4 Replies)
Discussion started by: dunstonrocks
4 Replies
Login or Register to Ask a Question