how can i check if text file is closed ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how can i check if text file is closed ?
# 8  
Old 07-03-2006
Quote:
Originally Posted by umen
on sunos solaris when i do fuser -u myfile.txt
the output is :
myfile.txt:

what is wrong here?
pls read the 'man' pages first!!!!
# 9  
Old 01-12-2007
Quote:
Originally Posted by tansha
Hello,
content deleted by reborg

These kind of "words" are strictly not permitted in the forum.

Moderators! Please --->

Last edited by reborg; 01-12-2007 at 05:35 PM..
# 10  
Old 01-12-2007
# 11  
Old 01-12-2007
Quote:
Originally Posted by jim mcnamara
Code:
#!/bin/ksh
in_use=$(fuser -u /path/to/file/filename)
if [ ${#in_use} -gt 0 ] ; then
   echo "file in use"
else
   echo "file not in use"
fi

I have few objections with the above!

on the same node with two different sessions,
I ran the following

session I
>
Code:
while :
do
echo "a" > file1
done

session II
>
Code:
while :
do 
fuser -u file1; echo $?
sleep 1
done


the output really alternates between being used -> not being used


from the man pages of fuser,
fuser returns a non-zero return code if none of the specified files is
accessed or in case of a fatal error. If at least one access has been
found, fuser returns zero.
# 12  
Old 01-12-2007
Hi Aigles,

I tried your script, but it is always returning me the result as " File is available", though the file is still being written to. It is a large file which takes quite some time to get ready.

So how can I know when the file is completely ready?

Thanks again for you assistance
# 13  
Old 01-12-2007
lsof (to my knowledge) isn't part of non-GNU coreutils. It would work just fine for this problem.

My version of the man page for fuser states "open files or active file structures"
meaning that until the data is actually physically written to disk, fuser could return 0.
Which is what you see. fuser is really meant more for sysadmin use than just playing with open files like lsof does.
# 14  
Old 01-12-2007
Hi Jim,

when I run lsof, all I could get is the following:

lsof: WARNING: compiled for AIX version 5.1.0.0; this is 5.2.0.0.

So the next step would be to update my version for lsof for AIX 5.2.0.0 ??? Unfortunately at this stage there is no plan for any system updates and I am one of the developpers team, so any other workaoround solution please?

Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check if files inside a text file are found under a directory

Hi all, Please somebody help me with this: I want to check if the files listed in a text file, are found under a directory or not. For example: the file is list_of_files.txt, which contains inside this rows: # cat list_of_files logs errors paths debug # I want to check if these... (3 Replies)
Discussion started by: arrals_vl
3 Replies

2. Shell Programming and Scripting

[Solved] Replacing line of text while file is closed

Is it possible to replace a line of text within a file while it's closed with a single command or a script? Please show me an example or point me to a webpage that shows an example. The file has this line of text: LoginGraceTime 100 I want to replace it with the following: ... (2 Replies)
Discussion started by: wdg74
2 Replies

3. Shell Programming and Scripting

Check if the text file has more than 2 characters

Guys, I know that the below command will cut the 13th field from test.txt file awk -F"|" '{print $13}' test.txt The answer would be, CA CN Ohio If we see the 3 rd one, it has more than 2 characters. So i wanted to check this in if condition and i want to get the output if the 13th... (4 Replies)
Discussion started by: AraR87
4 Replies

4. Shell Programming and Scripting

Shell program to check if the same text appears twice in an XML file

Hi All, I am very new to this forum and beginner to shell scripting. I need a shell script to: Search for a text in XML file à if the same text appears twice in an XML file à output file name Script should loop thru every xml file of a given folder. Please help me writing this script. ... (1 Reply)
Discussion started by: amardeep001
1 Replies

5. Shell Programming and Scripting

need to wait until Text Editor is closed

Hi, I am writing an SH script where I need to open text editor from within the script and wait until the user closed or quit text editor. And then execute consecutive commands. Here is a very simplified example: gedit data.txt # ---- wait until Text editor is exited echo "Text Editor is... (1 Reply)
Discussion started by: dd_u_dev1982
1 Replies

6. Shell Programming and Scripting

shell script to take input from a text file and perform check on each servers and copy files

HI all, I want to script where all the server names will be in a text file like server1 server2 server3 . and the script should take servernames from a text file and perform copy of files if the files are not present on those servers.after which it should take next servername till the end of... (0 Replies)
Discussion started by: joseph.dmello
0 Replies

7. Shell Programming and Scripting

Check if a text file is empty or not (using ls -s)

Hello, I want to make a script which says if a text file is empty or not. I tried two ways of making it, but I have problems with both of them. Now I think that the better way is the ls -s solution (considering that an empty text file has a 0 weight, because "cat file.txt" fails when file is... (4 Replies)
Discussion started by: Link_
4 Replies

8. Shell Programming and Scripting

Need a script that will check for changes in a text file

Hi Everyone, Can someone please show me how to create a script that will search a text file for changes. For example below is a sample of how the text file would look like, RLH rlh-1 ALIVE 20:06:05 RLH rlh-7 ALIVE 20:06:05 RLH rlh-3 ALIVE ... (7 Replies)
Discussion started by: kumaran21
7 Replies

9. UNIX for Advanced & Expert Users

How to check a file in UNIX is closed or growing?

We have a third party tool in UNIX to kick off a 'file copy' job based on a file existance. If a specific file exists in an UNIX directory, another process should start copy the file into another system for further processing. The issue is, the copy job is starting as soon as the file exists in... (6 Replies)
Discussion started by: kslakshm
6 Replies

10. UNIX for Dummies Questions & Answers

How to check if a unix text file is being accessed?

I am writing a script that periodically reads in data from a text file. The only issue is that, that text file is periodically updated (appended to) by another script. I am using perl in UNIX environment. How can I check if that text file is being accessed, so I can wait until it is no longer being... (6 Replies)
Discussion started by: rickylui
6 Replies
Login or Register to Ask a Question