Visit Our UNIX and Linux User Community

Script that waits until a call is done

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script that waits until a call is done
# 1  
Old 08-21-2009
Script that waits until a call is done

Hi all,

I have a script that checks for the existence of files in a directory. Problem is,
if a file suddenly appears, I need to move it to another directory and then
call another program that does not import routines (within our DBMS).

Now, this script is ever running and uses the sleep command to run every
second. Now, how would I be able to run the called process and wait
until it is done. I've tried the wait command, but its not successful as I
believe a new PID is being generated.

Here's what i have so far: (mind you, its messy)


# destscan_daemon - Program runs as a faux-service and looks for any files in the
# pickup directory designated in config. file and processes
# data in filePro. Results are dropped off in a directory
# also designated in config.
# usage: destscan_daemon [runs as daemon/service]
# set script configuration file

# read configuration file & variable declarations info script
if [ -s "${CfgFile}" ] ; then
. $CfgFile
echo "Could not start service! Configuration file missing!" >&2
exit 0
# start service. if anything exists in pickup, start processing
DoImport="my command to import"

if [ -d "${Pickup}" ] ; then
while true ; do
ls $Pickup -1 | while read line ; do
set ${line} ; EdiFile=$1
if [ $EdiFile != "" ] ; then
mv $Pickup/$EdiFile $ProcDir/$EdiFile
InFile=$ProcDir/$EdiFile ; export InFile
Stat=1 ; wait
if [ $Stat != 2 ] ; then
sleep 1

echo "Could not start service! $Pickup directory missing!" >&2
# 2  
Old 08-21-2009
I think you can let the service run in the background and check the process, for example, every 5s. If the process is finished then you execute your script.
Hope that helps.
# 3  
Old 08-22-2009
Are you using Linux? If so, you can install the inotify-tools package (project page). Then call inotifywait with appropriate switches and the file or directory name. It sleeps until there is a file event and then wakes up.

That's much better than polling.
# 4  
Old 08-24-2009
Originally Posted by KenJackson
Are you using Linux? If so, you can install the inotify-tools package (project page). Then call inotifywait with appropriate switches and the file or directory name. It sleeps until there is a file event and then wakes up.

That's much better than polling.
Thanks Ken!

I've just installed and I'm trying it out their examples.

Thank you again!

Previous Thread | Next Thread
Test Your Knowledge in Computers #78
Difficulty: Easy
Linux was inspired by MINIX
True or False?

10 More Discussions You Might Find Interesting

1. SuSE

Tcp waits

Hi Guys I am running an Oracle database and most of my sessions are waiting for tcp. Now, how do I check if tcp from the O/S level is servicing requests properly? Please Help!!! Thanks in advance... (4 Replies)
Discussion started by: Phuti
4 Replies

2. Shell Programming and Scripting

Script that waits for process to complete

Hello, I am in need of running an executable provided by a vendor that basically syncs files to a db. This tool can only be run against one folder at a time and it cannot have more than one instance running at a time. However, I need to run this tool against multiple folders. Each run of the... (5 Replies)
Discussion started by: vipertech
5 Replies

3. Shell Programming and Scripting

Call a Perl script within a bash script and store the ouput in a .txt file

I'm attempting to write a bash script that will create a network between virtual machines. It accepts three arguments: an RSpec that describes the network topology, and two list of machines (servers and clients). I have a (working) Perl script that I want to call. This Perl script takes an RSpec... (6 Replies)
Discussion started by: mecaka
6 Replies

4. Shell Programming and Scripting

Shell script to call Oracle archive backup script when file system reaches threshold value

Hello All, I need immediate help in creating shell script to call archivebkup.ksh script when archive file system capacity reaches threshold value or 60% Need to identify the unique file system that reaches threshold value. ex: capacity ... (4 Replies)
Discussion started by: sasikanthdba
4 Replies

5. Shell Programming and Scripting

Script to call a menu script and redirect each option to a text file

Hello, I want to design a script that will call an existing menu script and select options one by one and redirict the out put to a file. For example;- In the script there are 10 options i want to design a script that will select option 2 3 4 6 7 10 and redirict the output... (4 Replies)
Discussion started by: spradha
4 Replies

6. AIX

AIX CPU waits

Guys, I have a question - when nmon reports a sizeable %CPU wait, does that mean - 1) IO operations are slowing CPU down, OR 2) paging slowing the CPU down, OR 3) one cant tell?? I thought the nmon documentation clearly suggested that CPU waits reported in nmon were from disk... (4 Replies)
Discussion started by: getback0
4 Replies

7. Shell Programming and Scripting

how to run script? call other script? su to another user? make a cron?

Good morning. I am searching for "how-to"'s for some particular questions: 1. How to write a script in HP-UX 11. 2. How to schedule a script. 3. How to "call" scripts from the original script. 4. How to su to another user from within a script. This is the basics of what the... (15 Replies)
Discussion started by: instant000
15 Replies

8. Programming

Runtime.getSystem.exec() function waits for child

Runtime.getSystem.exec() waits for child process to complete .. I do not want to wait for the child process to complete ..what is the option which has to be used ? (2 Replies)
Discussion started by: shafi2all
2 Replies

9. Shell Programming and Scripting

shell script executes program, but waits for a prompt

Sorry, newbie here. I have the following shell script which basically executes the sh-n-body.i686 program a specified number of times. However, before the sh-n-body.i686 begins its calculations it prompts for input from the user. In this case the user would have press ". return" and... (7 Replies)
Discussion started by: lionatucla
7 Replies

10. IP Networking

ftp waits for longer time to reply

If i fire followin command on unix (linux/solaris) and windows ftp serverX where serverX is not in the network, it takes more time to get reply on unix(3-4 mins) rather windows(1 min), can anybody tell me why this happens? and how to reduce this time span? (1 Reply)
Discussion started by: amolwar
1 Replies

Featured Tech Videos