![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Delete an empty file from dir. | Script40 | Shell Programming and Scripting | 2 | 04-02-2008 02:09 PM |
| The output file is empty. Please Help | balzzz | UNIX for Dummies Questions & Answers | 4 | 01-31-2008 09:15 PM |
| empty file in hp-ux | Mizi | UNIX for Advanced & Expert Users | 2 | 08-09-2006 03:29 AM |
| Deleting the empty file | rkumar28 | Shell Programming and Scripting | 2 | 05-03-2006 11:05 AM |
| File exists and is empty | dstinsman | UNIX for Dummies Questions & Answers | 5 | 02-09-2006 07:05 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
How do I check to make sure a file is not zero bytes?
Something like: if [ !-z $filename ] then ????? |
| Forum Sponsor | ||
|
|
|
|||
|
lesstjm is asking how to make sure a file is not zero bytes. I think he wants to test actual file content, in which case he will want the -s option. But since the sample code used a variable, that leaves the door open to the other interpretation of wanting to test content of the variable instead of the file it references.
So just to clarify, -s will test the file itself for content, and -z and -n will test the contents of the variable. |
|
|||
|
How can I test if a file is opened by a process?
I have the following situation: a process (suppose I don't know anything about it) writes data into a file very very slowly. I want to copy the file to another location ONLY after the process closes the file (and I want to be very sure about that). I've tried to check the file size from time to time but this method doesn't always work. I've also tried with test -N file where −N file is true if file exists and was modified since last read but I can't figure out how this works. Can anyone give a clue? Thanks! |
|
|||
|
Not sure if fuser will work on all flavours of UNIX.
This will loop until the file is copied. It will check every 60 seconds to see if the file is still locked and copy it when it's unlocked. I haven't tested this #!/bin/ksh Status=1 while [ $Status -ne 0 ] do sleep 60 ProcID=`/usr/sbin/fuser filename | awk -F: '{print $2}'` if [ "$ProcID" = "" ] then cp filename somewhere fi Status = $? done ######################## Matt. |