Shell Script to launch C program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script to launch C program
# 8  
Old 03-29-2010
thanks again for the replies. when i use the terminal and use the following code

./monitor fname

results are displayed in the terminal window detailing any changes to the files that are being monitored (i.e. file altered, file deleted etc.) Although my script is the same as the post above, my results are not being shown. neither in the terminal or in the shell script (where i would rather they were)

thanks again
# 9  
Old 03-31-2010
Question

any ideas of what i need to make the results display? iv ran some tests and the shell script gets stuck sayin "Is this the correct file you wish to monitor?" if you type "y", it just keeps asking the same thing...

gary
# 10  
Old 03-31-2010
Quote:
any ideas of what i need to make the results display? iv ran some tests and the shell script gets stuck sayin "Is this the correct file you wish to monitor?" if you type "y", it just keeps asking the same thing...
You are not breaking out of the while loop after a [Yy] choice is made, so you loop through again, with the "are you sure" question. If you answer Y or y again, you'll launch yet another monitor for the same file.

You should probably add a statement that the monitor was launched for the file the user asked for and then exit the script after actually launching the monitor, unless you want to ask for a different file, in which case you need to re-work your loop a bit.

The "*" on both the [ Yy ] and [ Nn ] choice seems odd. Better to just have '[ Yy ])' and '*)' as choices for your case statement.
# 11  
Old 04-01-2010
yes that sounds like what i need. although how to i make so that the program displays the output, cos i can imagine if i add a statement asking "are you finished" i'll probably get stuck in that loop. or would the results be displayed after i the monitoring was finished, the way it runs now is live so as the file is altered, the terminal is updated.

on the "*" part of your post, im not too familiar with shell scripts, and didnt know you could do it another way.

any more help would be incredible
# 12  
Old 04-01-2010
Taking the code you had and reworking it a little, and adding another case statement and prompt you could do this:

Code:
while true; do
read -p "please enter the file you wish to monitor" fname
read -p "are you sure you want to monitor the file: $fname? (Y/N)" yn

  case $yn in
    [Yy]) if [ -d $fname ]; then 
              ./desktop/monitor $fname &
              echo "monitor for $fname launched."
            fi;;

    *) echo "exiting script" 
        exit;;
  esac

  # if you got here, you've launched a monitor
  # so ask if another one should be launched

  read -p "Do you want to launch another monitor? (Y/N)" yn

  case $yn in
      [Yy]) ;;         # leave case statement and continues the while loop
           *) echo "Exiting script"
               exit ;;
  esac

done

Basically you only handle the [Yy] condition in the case statements anything else exits the script. You can handle the [Nn] condition if you really want to, but what should happen if the user picks something other than [Yy] or [Nn]? The '*' is the default action if none of the other actions enumerated are picked. Since I've only enumerated the [Yy] anything else will exit the script.
# 13  
Old 04-11-2010
hi, sorry for late reply, iv been away.

iv input you code and its helped alot, although im still not gettin the output. ran in the terminal without script works fine, but obvs i want it as my gui.

so im thinking, is there a way to use the shell script to load my monitor prog in the terminal and for it to bring the terminal up, to see results, or even better, in the script window itself. its a constant monitorin program and therefore it always updating...

thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Launch shell script with parameters from a webpage button

I want to create a simple html page that should contain 2 fields in which the user can write the input. Then I want to have a button that should launch a shell script with the parameters inserted by user in the fields from the webpage. This is the code behind my webpage: <html> <form... (2 Replies)
Discussion started by: black_fender
2 Replies

2. UNIX for Dummies Questions & Answers

Launch shell script if string match is found

I'm trying to write a simple shell script that looks at a given text file and if the only word in the file is 'completed', it launches another shell script. So far I have this almost working... if grep 'completed' $datafile then... however, using this logic the secondary shell script... (3 Replies)
Discussion started by: MickeyGreen
3 Replies

3. Shell Programming and Scripting

Perl script timer on program launch

So I am attempting to get a short but complex perl script to be able to time out an application that I will launch from a command line. The terminal I use is MKS C SHELL and I am having trouble doing the a job spawn that will launch the application and keep time on it. I know you could do this... (1 Reply)
Discussion started by: vas28r13
1 Replies

4. Shell Programming and Scripting

Launch a windows program from perl script

Hi i wanted to know if any one can give me an example on how to launch a windows program in a perl script. I wanted to open the nmap software on my computer with a perl script, i heard this can be done with the system function. Would the function be in this format: $text =... (1 Reply)
Discussion started by: kingbp
1 Replies

5. Shell Programming and Scripting

launch vnc session from unix shell script

Hi All, OS:AIX 64 bits Would like to know what is the command to launch vnc session from unix shell script so that Reports server is started from vnc session which should be launched from within the shell script. Thanks for your time! Regards, (0 Replies)
Discussion started by: a1_win
0 Replies

6. Programming

Problem with external program launch

Hello, in the application i'm writing i need to launch "recordmydesktop" to capture the screen,but i'm having a problem: when the recording stops,and the encoding of the saved file starts,the entire system hangs until the completion of the encoding.This happens if i launch recordmydesktop from my... (7 Replies)
Discussion started by: Zipi
7 Replies

7. UNIX for Advanced & Expert Users

Can we launch a shell script automatically upon ssh login?

Greetings all, I'll just like to know if it is possible to launch a shell script automatically upon a user's successful login into ssh from a remote host, without adding a command parameter to the ssh command... ie. after keying in ssh username@host (not ssh username@host "command") and upon... (1 Reply)
Discussion started by: rockysfr
1 Replies

8. Shell Programming and Scripting

How to launch a Csh shell script using Excel Macro ?

Hi all. I need to use excel macro at my desktop to launch a csh script which is in a solaris environment. What is the code that i can use in macro to help me with that ? Basically, the code need to telnet or ftp to the solaris environment and just run the script and the macro will output in an... (1 Reply)
Discussion started by: Raynon
1 Replies

9. Programming

launch an executable from a C++ program

Hi everybody! Could you please tell me how can I launch an executable from a C++ (on unix) program? thanks in advance! (2 Replies)
Discussion started by: nadiamihu
2 Replies

10. UNIX for Dummies Questions & Answers

how to launch program though telnet

I have launched telnet on nt and have connected to a unix server, I'm trying to run a program on the unix server which will launch a gui, but when I try to launch it I get the message "display not set\n" "By default set it to 0.0" I can sit down at the unix machine and launch the program with... (3 Replies)
Discussion started by: cbachman
3 Replies
Login or Register to Ask a Question