Shell script to execute condition until an event occurs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to execute condition until an event occurs
# 1  
Old 07-17-2013
Shell script to execute condition until an event occurs

I need a script to keep polling "receive_dir" directory till "stopfile" get written in the directory.

This has to run despite empty directory.

So far i have this but fails if receive_dir is empty with no files with "unary operator expected". Help !!

Code:
#!/usr/bin/ksh

until [ $i = stopfile ]
 do
   for i in `ls receive_dir`; do
   time=$(date +%m-%d-%Y-%H:%M:%S)
   echo $time
   echo $i;
  done
done

# 2  
Old 07-17-2013
It's because "$i" is initially undefined. Quoting it gets around this.

Code:
#!/usr/bin/ksh

cd $receive_dir
until [ "$i" = stopfile ]
 do
   for i in *; do
     time=$(date +%m-%d-%Y-%H:%M:%S)
     echo "$time"
     echo "$i"
  done
done

for i in `ls receive_dir`; do will produce an error if no files exist, and for i in *; do resolves to * if no files exist, and it seems a bit wasteful to scan a whole directory to look for a known file, so it's probably better just to check if the file exists.

Code:
until [ -f $receive_dir/stopfile ]

(not forgetting to add a sleep to the loop)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If condition shell script beginner

Hi all I have the folloing process that needs checking often: ps -ef | grep ih bscsrtx 206 15901 0 11:28:10 pts/6 0:00 fih -r4 bscsrtx 218 15901 0 11:28:27 pts/6 0:01 aih bscsrtx 29763 15901 4 11:27:16 pts/6 0:59 rdh -prih root 429 27268 0 11:30:15 pts/td ... (13 Replies)
Discussion started by: fretagi
13 Replies

2. Shell Programming and Scripting

Need Help to add Condition in Shell Script..

Hi Team, I m very new to shell scripting , i want to add following condition in my script . Can anybody help me. There are three port in My node "$port" port_A port_B port_C I Want to add following Conditions in my script. If Node is connected to port_A and port_B script... (10 Replies)
Discussion started by: Ganesh Mankar
10 Replies

3. Shell Programming and Scripting

Shell script to poll a directory and stop upon an event

Need shell script to: 1/keep polling a directory "receive_dir" irrespective of having files or no files in it. 2/move the files over to another directory "send_dir". 3/the script should only stop polling upon a file "stopfile" get moved to "receive_dir". Thanks !! My script: until do... (0 Replies)
Discussion started by: iaav
0 Replies

4. UNIX for Dummies Questions & Answers

While condition in shell script

while do if ;then read driverName else driverName="" fi done can anyone please explain what exactly is happening on 1st line...is it like the conditions being ORed...I have no clue about this. (4 Replies)
Discussion started by: rtagarra
4 Replies

5. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

6. AIX

if condition in AIX5.3-10 shell script

True if file exists and has been modified since it was last read. if then command else exit fi i am on AIX5.3-10. it does not understand -N any other way. i can use -ot (file1 is older than file2), but prefer -N if possible. (3 Replies)
Discussion started by: tjmannonline
3 Replies

7. UNIX for Advanced & Expert Users

Truncation Occurs When Outputting Shell Script to stderr

Operating System: Solaris 10, Shell We are outputting the results of our scripts to the stderr file. However we have encountered a problem where some of the lines in the file are truncated. Is there a way to increase the terminal or column size within the script so that this does not... (4 Replies)
Discussion started by: fazzasx
4 Replies

8. UNIX for Dummies Questions & Answers

Can we trigger an shell script on an event

Hi, My program A updates a log called logA. I have a shell script S that is responsible to send emails reading from the log. I want to trigger execution of the script whenever there is an update to the log. Thanks in advance. (8 Replies)
Discussion started by: cv_pan
8 Replies

9. Shell Programming and Scripting

keypress event in shell script

Hi All, How can I trap a character press in the shell script. For eg:- I have a script runinng a infinite loops , I will need to dispay menu asking for run process of to stop process and process stauts like we do in glance I have seen the traping the signal in glance command, (8 Replies)
Discussion started by: arvindng
8 Replies

10. Programming

Cannot catch SIGINT while serial break condition occurs

I setup termios structure with IGNBRK is not set and BRKINT is set. To allow the process to receive signals I call: fcntl(fd, F_SETOWN, getpid()); I have made a signal handler to catch all signals. I can catch SIGINT when pressing ctrl+c but when I send break signal over serial then it cannot... (13 Replies)
Discussion started by: gzz
13 Replies
Login or Register to Ask a Question