Execute a command after a program was launched

Hi Experts,

I am creating a script to monitor a certain applications running in my Unix system.

My script order goes this way:

df -h /of/a/filesystem

tail -5 /path/to/an/application/availability

su -c "jsmon pf=(profile of my application) `echo "p"`" usradm

#EOF

I am encountering problem on my 3rd line. Basically what I wanted is when
my script run, it switches to user "usradm" execute command " jsmon pf=(profile of my application " and then echo the letter "p".

My script runs the switch to usradm command and executes program " jsmon pf=(profile of my application) " however won't execute "p" command after and getting error like:

 JStart Monitor Program
                                                                               jsmon=>appparam(2): fopenU("/home/usradm","r"): No such file or directory
jsmon=>No Profile used.
jsmon=>appparam: SYSTEMNAME neither in Profile nor in Commandline

 Thu Oct 20 06:45:30 2016 (initial: p)
  JsfOpenShm failed: object not found
  Cannot access shared memory.
 Thu Oct 20 06:45:30 2016>

Please help.

Thank you!

You're not getting usradm's environment, just your old environment, try

su - -c pf=(profile of my application) `echo "p"`" usradm

I cannot divine the intention of `echo "p"` so I'm guessing that was abridged for some reason. What is it really doing?

If you want to execute the echo command after jsmon finished you have to separate the 2 commands. Otherwise jsmon is called with an additional parameter with the value p.

su - -c "jsmon pf=(profile of my application); echo p" usradm

Hello Corona688,

Thanks for your response.

I tried your suggestion but I'm still getting the same error as before.

To answer your question about `echo "p"` once the user enters the program and input "p" (short for print) it lists all the server status of the application.

---------- Post updated at 05:07 PM ---------- Previous update was at 04:55 PM ----------

Hello cero,

Thanks for your response.

When I tried to seperate the two commands, it executes echo p command after exiting the program.

Sequence goes like this:

su - -c "jsmon pf=(profile of my application); echo p" usradm
  1. switches to usradm
  2. launches the program jsmon
  3. doesn't print "p"
  4. when exiting the program, it then prints "p"

exampe:

Fri Oct 21 07:01:54 2016> quit

p

once a program is launched, is it impossible to execute a command inside the program environment?

Just guessing that you want to feed jsmon the "p" character. If it is reading from stdin, you might be lucky: Try

"echo p | jsmon pf=(profile of my application)"

If it doesn't, things may become tedious...

Hello RudiC,

Thank you.
It worked, but now it continuously print "p". Tried adding " | echo quit " after jsmon pf=(profile of my application) but it returned quit command

example:

quit
[1] 22894 22895 

Is it possible to stop inputting "p"? one time is more than enough.

It should NOT pipe more than exactly one single "p" to jsmon . Try

printf "p\nquit\n" | jsmon pf=(profile of my application)

Hello RudiC

Thanks for your response.

printf "p\nquit\n" | jsmon pf=(profile of my application)
  • this time it doesnt "print" the list of servers but continuously run the command. even ctrl+c, q+enter, ctrl+d doesn't stop it.
echo p | jsmon pf=(profile of my application)
  • pretty much does what I wanted, its just that it continuously execute the command and doesnt end it even with ctrl+c, q+enter, ctrl+d.

tried testing a similar command in a test directory

echo y | rm -i * 

and it just remove the 1st file inside the directory. which is confusing when im trying to

echo p | jsmon pf=(profile of my application)

that runs endlessly. don't know why it keeps on executing "p".

:frowning: