Minimize /reduce disk reading/ writing in BASH scripting
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Minimize /reduce disk reading/ writing in BASH scripting
Hi
I'd like to minimize disk operations in BASH script when executing my freshly written script, which depends on writing outputs to file and then processing with grep, awk..
It is possible to read all the output from commands to the variables, BUT (yes, there's always one )
then the data in variables doesn't retain the formatting.
I'm attaching my script and outputs that I get in the files for better explanation what the script does.
I would like the script not to make so much writing to disk if the RAID fails (because at that moment it's fairly high disk usage getting Rebuilding the RAID set)
and get the output to a variable and process then all from memory, not the file.
huh, I hope for some explanation if anyone could lead me
Use a tmpfs mount (/tmp ?) and write the file out to real disk (if needed) as a final operation in the script.
I would have thought it should be retained in cache anyway ...
A parameter will store any character except the null-byte, which is discarded. Whatever characters you put into a variable will stay there as-is until you declare a new value for it or unset it. This includes spaces, tabs, newlines, and other control characters.
If your formatting isn't being preserved, it's almost certainly due to the shell processing whitespace after the variable expansion. Always be sure to double-quote your variables to keep this from happening.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Quote:
Originally Posted by lithos
I'd like to minimize disk operations in BASH script when executing my freshly written script, which depends on writing outputs to file and then processing with grep, awk..
I admit I am too lazy to read throught your script on the disk usage. How much disk usage do you call a lot? Hard disks now have a few MB of cache, and unless your script is creating bulk output, script output is usually measured in kB. You won't notice.
I admit I am too lazy to read throught your script on the disk usage. How much disk usage do you call a lot? Hard disks now have a few MB of cache, and unless your script is creating bulk output, script output is usually measured in kB. You won't notice.
jlinkels
+1 to that.
Linux buffers file system writes (unless it is configured not to) and then the storage devices buffer their writes.
The only time I had an issue with script logging was on an IBM geo-cluster (maybe not the right term -- it was a long time ago) which was configured for maximum file system data retention so any file system write was immediately sent over the network to the remote mirroring server.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.