APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Home > News Posts > Synchronous hard drive writes from shell script ––>Re:Disk write shell script
Printer Friendly Version




News Group Posts

Synchronous hard drive writes from shell

script


Newsgroups: comp.unix.sco.misc
From: "Radek Tomis" <rts@mediumsoft.cz>
Subject: Re: Disk write shell script
        charset="iso-8859-2"
Cc: "Fabio Giannotti" <fabiog@venmar.com>
Date: Thu, 5 Aug 1999 13:01:54 GMT
Message-ID: <023b01bedf44$65984240$8e0314ac@rtsnt> 
References: <37A8C3D4.25EFC00C@venmar.com> 

> From: Fabio Giannotti <fabiog@venmar.com>
> Sent: Thursday, August 05, 1999 12:51 AM

> Is there a way using bourne shell to write directly to the hard disk?
>
> That is to say, if you write a "regular" shell script that writes 100
> lines to a file, it may only hit the disk 1 or 2 times.  I assuming it's
> buffering or caching a bunch, then writing a bunch all at once.
>
> What I want is for each line written to "go right to disk" and not be
> buffered/cached.
>
> Any ideas?



If you want transparent synchronous output, then download this 35 KB binary:

  http://members.xoom.com/rts101/tmp/fildes

and use it inside (or outside) of your script in one or more of the
following ways:

1. Inside your script for individual output commands:

     fildes 1=~,A+S : echo "line" >> /tmp/file

   This will append "line" to "/tmp/file" synchronously (i.e. the line will
   be physically written to the disk drive before the command 'echo'
   returns).














   Consider the following example using different output command:

     fildes 1=~,S : tail -300 /usr/adm/messages > /tmp/file

   This will synchronously append last 300 lines of "/usr/adm/messages"
   to "/tmp/file. However, 'tail' (and almost all other commands/utilities)
   uses user-level standard buffered I/O (from standard C library), and if
   the output is directed to something other than a terminal device, then
   the output is buffered by constant block size, usually 1 KB (depends on
   implementation). So, the 'tail' above actually writes (calls kernel
   routine write(S)) to "/tmp/file" only once per 1 KB (no matter whether
   this happens to be in the middle of the read line or not). In this case,
   each such 1K block gets written synchronously (the 1K block physically
   appears on the disk drive before the write(S) call returns).


2. Inside your script for several output commands at once:

     fildes 1=/tmp/file,A+S : sh -c '(
       set -- comp unix sco misc
       echo "`date`: arguments:"
       for arg
       do
         echo "  arg: ${arg}"
         sleep 1    # some processing
       done
     )'

   This will append several lines to "/tmp/file". Each line will be written
   synchronously (the line will be physically written to the disk drive
   before the command 'echo' returns).


3. Outside of your script for the entire script:

     fildes 1=/tmp/file,S : <your_script>

   This will run your script with standard output redirected to "/tmp/file".
   Every standard output from your script (and all its children, i.e. all
   external commands used within your script) will be synchronous, i.e. all
   underlying write(S) calls completes after all data in the given write(S)
   call have been physically written to the disk drive.


You can also use standard system command 'sync' after each line output,
however, it will write out not only this last line to the disk, but also all
other dirty file system blocks from system memory buffers for all file
systems. Depending on the recent write activity in the system, it may of
course take much longer than actually needed for your one-line write.

--
Radek Tomis
rts@mediumsoft.cz



If this page was useful to you, please click to help others find it:  

Your +1's can help friends, contacts, and others on the web find the best stuff when they search.

Comments?



Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

g_face.jpg

This post tagged:

       - Disks/Filesystems
       - Kernel
       - Programming
       - SCO_OSR5
       - Scripting




Unix/Linux Consultants

Skills Tests

Guest Post Here