![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Pls Help-Script to execute Commands and write to excel file | Computer_baby | Shell Programming and Scripting | 1 | 01-08-2008 08:34 AM |
| How to execute the rest of the code after commenting multiple lines? | Yamini Thoppen | Shell Programming and Scripting | 12 | 01-02-2008 12:50 PM |
| script execute or no execute | Kespinoza97 | Shell Programming and Scripting | 4 | 06-23-2007 09:27 AM |
| Need to execute 2 scripts, wait, execute 2 more wait, till end of file | halo98 | Shell Programming and Scripting | 1 | 08-01-2006 04:42 PM |
| How to execute a .sql file with shell script | abuanas | Shell Programming and Scripting | 2 | 04-26-2006 04:16 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
|||||
|
The following code waits for existence of a file.
Code:
required_file=/path/to/file test_interval=30 while [ ! -f $required_file] do sleep $test_interval done echo "File $required_file available." Code:
required_file=/path/to/file test_interval=30 until[ -f $required_file] do sleep $test_interval done echo "File $required_file available." |
|
||||
|
but wht if the file that is getting created is a big file and it takes some time for that file to get created, then the above codes wont help....i am teling this from my experience
but i dont understand why we have to do anything....(like [ ! -f filename ]) because the following will also work fine Code:
head -100 abc.txt > temp # where the file gets created wc -m temp > count # the rest of the code someone please clearify......... |
|
|||||
|
Quote:
A possible solution is to add a test to control if the file is opened by a process (bulletproof) : Code:
required_file=txt.txt
test_interval=30
while true
do
if [ -f $required_file ]
then
echo "$0 - File exists !"
if fuser $required_file 2>&1 | awk -F':[[:space:]]*' '{exit ($2=="" ? 0 :1)}'
then
break
else
echo "$0 - File in use !"
fi
fi
sleep $test_interval
done
echo "File $required_file available."
Instead of checking the file existence, le waiting process check the flag file. Quote:
If the file doesn't exist, the head command will fail. Jean-Pierre. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|