Execute a command after a program was launched


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute a command after a program was launched
# 1  
Old 10-20-2016
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:

Code:
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:

Code:
 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!



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 10-20-2016 at 05:58 AM.. Reason: Added CODE tags.
# 2  
Old 10-20-2016
You're not getting usradm's environment, just your old environment, try
Code:
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?
# 3  
Old 10-21-2016
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.
Code:
su - -c "jsmon pf=(profile of my application); echo p" usradm

# 4  
Old 10-21-2016
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:

Code:
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:

Code:
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?


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 10-21-2016 at 06:19 AM.. Reason: Added CODE tags.
# 5  
Old 10-21-2016
Just guessing that you want to feed jsmon the "p" character. If it is reading from stdin, you might be lucky: Try
Code:
"echo p | jsmon pf=(profile of my application)"

If it doesn't, things may become tedious...
# 6  
Old 10-21-2016
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:
Code:
quit
[1] 22894 22895

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

Last edited by Don Cragun; 10-22-2016 at 10:24 AM.. Reason: Add CODE and ICODE tags.
# 7  
Old 10-21-2016
It should NOT pipe more than exactly one single "p" to jsmon. Try
Code:
printf "p\nquit\n" | jsmon pf=(profile of my application)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Program Does not execute

Hi there, When I am trying to execute any shell script. The shell script only execute line 1 and I notice that the rest o the program was not executed. Please advise. # bash +x vmscript-4.sh Even when I enter this command there is not output. sudo su cd /tmp cp... (2 Replies)
Discussion started by: alvinoo
2 Replies

2. Ubuntu

I can't execute a C++ program, help!

My professor gave me a code with no errors. When I compile it's fine, it doesn't show any errors, but when I try to execute it shows this: line 3: syntax error near unexpected token '(' line 3: 'int main()' I searched through the Internet but I couldn't find any solution. Please!!!... (1 Reply)
Discussion started by: rosiiieee
1 Replies

3. Shell Programming and Scripting

Execute a C program from Shell

Hi I want to create a shell script tha executes a C program and then retrieves information about it. I managed to run the program with: #!/bin/bash gcc -o program program.c ./program Now i want to get the id of the process (pid) Any help would be appreciated, Thank you (18 Replies)
Discussion started by: nteath
18 Replies

4. UNIX for Advanced & Expert Users

Which script/shell/program launched a given script?

Dear gurus, I was wondering if anybody can help. Is it possible to distinguish whether a script was launched from a shell (interactively) or was called from another script? I basically need to do the following: if the script was run from the command line, I want to enable logging of the... (2 Replies)
Discussion started by: Snakeye
2 Replies

5. UNIX for Dummies Questions & Answers

how to execute program without using ./ or sh

Hi, I am a complete newbie for unix. I have just installed mysql on my MAC. I was wondering every time I wanted to use mysql I had to ./mysql or sh mysql everytime on /usr/local/bin/mysql/bin. How can I execute the mysql program without using ./ or sh. I chmod +x already. And what do I have to... (3 Replies)
Discussion started by: noppanit
3 Replies

6. Shell Programming and Scripting

Kill remote application launched via SSH command

Hi All I launch some application in a remote machine using ssh EXAMPLE ssh -X myname@mycompany@RemoteServerIp 'myApplicationName' When I want to kill the application I hit CTRL+C and I see a message 'Killed by signal 2'. Unfortunately on the remote machine the application is not really... (1 Reply)
Discussion started by: manustone
1 Replies

7. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

8. Shell Programming and Scripting

how to execute this program?

Filesystem 1024-blocks Free %Used Iused %Iused Mounted on /dev/hd4 32768 16016 52% 2271 14% / /dev/hd2 4587520 1889420 59% 37791 4% /usr /dev/hd9var 65536 12032 82% 518 4% /var /dev/hd3 819200 637832 ... (1 Reply)
Discussion started by: sathyaac
1 Replies

9. Programming

execve to execute a program

I tried using the following code to execute a program but it doesnt seems to be working .. I would like to know whats wrong wit it . execve("/bin/cat", "words", NULL); (0 Replies)
Discussion started by: winsonlee
0 Replies

10. UNIX for Dummies Questions & Answers

Urgent!! How to write a shell program to execute command to access internet?

hi, I am new ot unix. So, can i write a shell(c shell or korn shell) program to access internet? I mean if I run the program, it can access specified url and then copy the html to a file? Can anyone help me? And how can make the program runs every 1 hr? new comer (2 Replies)
Discussion started by: firebirdonfire
2 Replies
Login or Register to Ask a Question