Run interactive program in background and grep it


 
Thread Tools Search this Thread
Top Forums Programming Run interactive program in background and grep it
# 1  
Old 06-20-2012
Run interactive program in background and grep it

I need to run an interactive program in the background so I can grep it for specific data to use for some logic in a script.

There is no quiet or background mode on the program so I plan to redirect a document with commands in it and then to grep the output.

This is almost working, except that then some lines I haven't grepped for are also appearing - this I don't understand - I thought grep would work on all output to STDOUT (I've tried redirecting STDERR too but that doesn't seem to help).

See example:
Code:
/usr/sap/XXX/SYS/exe/run/jcmon pf=/sapmnt/XXX/profile/START_JC10_bdhp4530 < txtj | egrep 'dispatcher|server|SDM'
 
[Thr 01] Wed Jun 20 06:54:01 2012
[Thr 01] MtxInit: -2 0 0
|  0|dispatcher          |   27390|Running             |    0|yes    |
|  1|server0             |   27391|Running             |    0|yes    |
|  2|SDM                 |   27392|Running             |    0|yes    |

Notice two lines which strangely get written to the output
[Thr 01] Wed Jun 20 06:54:01 2012
[Thr 01] MtxInit: -2 0 0

How are these getting there?
I thought there were only two channels for output to screen in UNIX
STDOUT
and
STDERR

However if I running the main command (without the egrep) and redirect either STDOUT (1>) or STDERR (2>) to /dev/null - then the ONLY lines that show up are those two lines - this works identically no matter which output of those two I redirect....
[Thr 01] Wed Jun 20 06:54:01 2012
[Thr 01] MtxInit: -2 0 0

Weird - any thoughts?

---------- Post updated at 12:38 ---------- Previous update was at 12:00 ----------

NB An alternate fix for my issue would be to be able to call a command but with a time limit -- i.e. if this command returns no output within 5 seconds then kill it.... any ideas on this alt? If I can find a thread on that alternative I'll link it in here.
# 2  
Old 06-20-2012
You want to redirect stderr to stdout, not /dev/null, i.e. 2>&1
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Interactive script with background

I have script, which need some variable from user and i use below command for this read this script works fine while running without background, but when i run this script in background, it ask first variable then immediately it show below error KSH variable not found please let me... (1 Reply)
Discussion started by: pallvi_mahajan
1 Replies

2. Programming

Non-interactive login using C program in UNIX(Solaris)

Hi i need a c programm to login in unix(solaris). non-interactivley because it seems difficult to do it with unix shell scripting and passwd command cant be used and also i don't have expect installed and i am not allowed to installed expect in our servers. is there any c programm that can help... (1 Reply)
Discussion started by: munish259272
1 Replies

3. Shell Programming and Scripting

Use expect to run an interactive shell script?

Hi all, I have a bit of a vexing issue here and I'm not certain how best to go about it. Basically, I want to run a shell script and automate the user prompt of hitting 1 to fully uninstall Symantec Anti-Virus for OS X. Would expect be the best way to do this? (5 Replies)
Discussion started by: prometheon123
5 Replies

4. Shell Programming and Scripting

scripting an interactive program session

Hello, I'm looking to script the basic instant messaging program we have in my company, it's called "oi", it's working as follow: # oi $user then we have to launch it... after finding the system of the user it's asking for the message... then on a new line we have to hit ctrl+d I... (2 Replies)
Discussion started by: nomadvisuals
2 Replies

5. Shell Programming and Scripting

How to process and run a program in the background in perl?

Hi, I have a query about processing and running Perl program at the background. I have HTML file called Userform.html which accepts input from the user. As soon as input is given the contol goes to get.cgi (get.cgi does some processing and computing tasks). Actually get .cgi takes more... (0 Replies)
Discussion started by: vanitham
0 Replies

6. Shell Programming and Scripting

Develop Program with 'None Interactive Flag'

Hi I have created a program but am currently wondering how to develop it further. I wanted to know how i would go about developing the program further so that it is able to run with a "none interactive flag" enabling execution to be automated with the resultant file e-mailed to a user once a week.... (1 Reply)
Discussion started by: warlock129
1 Replies

7. Programming

Run external program in background

Hi, in my program i need to run an external program in background.I am aware that there are at least 2 alternatives for this: 1)fork+exec 2)system("program &"); I have read several posts about this,and they all tend to suggest to use fork+exec (and that's what i am doing now). I have some... (2 Replies)
Discussion started by: Zipi
2 Replies

8. Shell Programming and Scripting

put an interactive script in background after taking input

i am trying to find a way to put an interactive script in the background after taking input from the user a few test lines i was trying: date echo "Enter location" LOCATION= read LOCATION sleep 100 sleep 200 date for this small example i want the script to as the user for the... (7 Replies)
Discussion started by: epsilonaurigae
7 Replies

9. Shell Programming and Scripting

Running an Interactive Program Remotely

now, i have a program that i would very much prefer to run remotely as i hate having to log into the box it is on. the problem is, every command i have tried to run this remotely doesn't work. the commands tries to kick off the program on the remote box but then hangs. like take for... (3 Replies)
Discussion started by: Terrible
3 Replies

10. Shell Programming and Scripting

Making Interactive program

Hi Friends I am trying to make an interactive shell script ( I do not have expect tool ) My objective is 1.I have a progam named say "inter" The program when ran on command prompt will be as below Prompt>inter Please enter the choice 1.enter 1 2.enter 2 < I need to enter 1 or 2... (4 Replies)
Discussion started by: sivasenthil_k
4 Replies
Login or Register to Ask a Question