sh script files

2013-02-20 Thread Fbsd8
I noticed that when power fails I loose the contents of some files I am 
using in a sh script.


I read and write the file this way

file=/usr/local/etc/filename

# read file
. ${file}

# write to file
 ${file}

I'm thinking the file is never closed so on power failure I loose the 
contents of the file.


How would I code a command to close the file?

Thanks
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: sh script files

2013-02-20 Thread Polytropon
On Wed, 20 Feb 2013 07:40:08 -0500, Fbsd8 wrote:
 # write to file
   ${file}
 
 I'm thinking the file is never closed so on power failure I loose the 
 contents of the file.
 
 How would I code a command to close the file?

The file is closed when the write operation has been
finished. You can use the sync command to flush
pending writes to the file (as writing is handled
asynchronously by the system). When the program
that writes to the file exits, it will close the
file it's writing to. This depends on the command
you're using infront of , as the command you've
shown will simply generate a null file (file with
no actual content).


-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: sh script files

2013-02-20 Thread Fbsd8

Polytropon wrote:

On Wed, 20 Feb 2013 07:40:08 -0500, Fbsd8 wrote:

# write to file
  ${file}

I'm thinking the file is never closed so on power failure I loose the 
contents of the file.


How would I code a command to close the file?


The file is closed when the write operation has been
finished. You can use the sync command to flush
pending writes to the file (as writing is handled
asynchronously by the system). When the program
that writes to the file exits, it will close the
file it's writing to. This depends on the command
you're using infront of , as the command you've
shown will simply generate a null file (file with
no actual content).




The problem is there may be a great time lag between reading the file 
and the writing to the file, IE: days or months depending on how long 
between host reboots. I would just like to close the file right after 
the file gets read.


Is there a way to code that?


___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org