LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-27-2014, 06:00 AM   #1
sreeharsha1988
LQ Newbie
 
Registered: Apr 2014
Posts: 17

Rep: Reputation: Disabled
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
 
Old 05-27-2014, 06:04 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,109

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
you should show us that script (or at least the important part). By default the shell waits for the programs until they are completed...
 
Old 05-27-2014, 06:54 AM   #3
sreeharsha1988
LQ Newbie
 
Registered: Apr 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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.
 
Old 05-27-2014, 07:47 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,109

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
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...
 
1 members found this post helpful.
Old 05-27-2014, 08:07 AM   #5
sreeharsha1988
LQ Newbie
 
Registered: Apr 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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.
 
Old 05-27-2014, 08:13 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,109

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
what about: echo -e "\x41"
echo -e "\x41" | <serial tty device>
 
1 members found this post helpful.
Old 05-27-2014, 08:31 AM   #7
sreeharsha1988
LQ Newbie
 
Registered: Apr 2014
Posts: 17

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
what about: echo -e "\x41"
echo -e "\x41" | <serial tty device>
So i presume 41 is the hexa data being transmitted to the device
 
Old 05-27-2014, 08:56 AM   #8
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,109

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
yes, and you can send more data by:
echo -e "\x41\x42\x43" | <serial tty device>
 
1 members found this post helpful.
Old 05-27-2014, 04:21 PM   #9
joe_2000
Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 808

Rep: Reputation: 216Reputation: 216Reputation: 216
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
 
1 members found this post helpful.
  


Reply

Tags
shell scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script programming steltner Linux - General 0 05-17-2003 08:00 AM


All times are GMT -5. The time now is 07:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration