LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell script and c programming (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-and-c-programming-4175506171/)

sreeharsha1988 05-27-2014 05:00 AM

shell script and c programming
 
I am trying to write a shell script and at a point the script launches a c program and how do I make the script to wait till that program is executed before executing the subsequent steps. As of now my script is not waiting until the program is completely executed and this is causing only a part of it being executed before the script completes execution

pan64 05-27-2014 05:04 AM

you should show us that script (or at least the important part). By default the shell waits for the programs until they are completed...

sreeharsha1988 05-27-2014 05:54 AM

Quote:

Originally Posted by pan64 (Post 5177465)
you should show us that script (or at least the important part). By default the shell waits for the programs until they are completed...

The code is as follows

#!/bin/bash
./finger/fingerprint /dev/ttyUSB0 /status.txt /template.txt;
wait

clear

fingerstatus=`cat /root/status.txt`
if [ "$fingerstatus" = "AUTH" ]
then
echo "successfully authinticated"
else
halt
fi

this is a part of my script which executes the compiled C program "fingerprint" and the next two lines are arguments passed to the program. This program when called communicates with a fingerprint device and tells if the finger is authenticated or not. This script runs as expected when called from a terminal but if included in the second stage of the boot process in init.d with symbolic links in rc2.d this script calls the program but exits before the program does its job. This is where I am stuck.

pan64 05-27-2014 06:47 AM

Hm. Actually it depends on how the program fingerprint works. If it detaches itself from the terminal you will not be able to wait for it. If it will not detach, you will not need to wait, because the command itself will not return as long as a fingerprint was detected. You know which one is true. In either case the command wait is not needed.
Furthermore you entered /status.txt to the program but checked /root/status.txt. I think that should be the same file...

sreeharsha1988 05-27-2014 07:07 AM

Quote:

Originally Posted by pan64 (Post 5177487)
Hm. Actually it depends on how the program fingerprint works. If it detaches itself from the terminal you will not be able to wait for it. If it will not detach, you will not need to wait, because the command itself will not return as long as a fingerprint was detected. You know which one is true. In either case the command wait is not needed.
Furthermore you entered /status.txt to the program but checked /root/status.txt. I think that should be the same file...

This is no relevant to the post but can you please tell me how would I transmit hexadecimal data using terminal commands to a serial tty device.

pan64 05-27-2014 07:13 AM

what about: echo -e "\x41"
echo -e "\x41" | <serial tty device>

sreeharsha1988 05-27-2014 07:31 AM

Quote:

Originally Posted by pan64 (Post 5177494)
what about: echo -e "\x41"
echo -e "\x41" | <serial tty device>

So i presume 41 is the hexa data being transmitted to the device

pan64 05-27-2014 07:56 AM

yes, and you can send more data by:
echo -e "\x41\x42\x43" | <serial tty device>

joe_2000 05-27-2014 03:21 PM

If the fingerprint command produced any output files you could wait for such files to become available. Like so:

Code:

while [ ! -f "outputfile.txt" ]; do
        sleep 1;
done



All times are GMT -5. The time now is 09:52 PM.