Writing a file to RAM within Bash and using it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Writing a file to RAM within Bash and using it
# 1  
Old 08-13-2007
Writing a file to RAM within Bash and using it

I've got a few scripts I use for various things, but there is one I have taking the output from a specific command, writing it to disk, and repeating for another command, then reading both (after some formatting) and writing the output to another file.

Part of the reasoning for writing to the two files before catting the output into the single file is to try and keep things organized since the two commands are running side-by-side (with &, of course).

What I'd like to know is if there is a good way to write the output from the two commands into RAM before catting/redirecting it into the lone file.

Anyone know of any good ways of doing this?
# 2  
Old 08-13-2007
Only as a file held on a RAM disk.

Alternatively while the data is in a pipe it is in RAM.

Sounds like you are actually wanting a temporary file that automatically clears itself up.

If you want to deal with memory etc, write a C program. Shell scripts deal at the process/program/file level.
# 3  
Old 08-13-2007
I was afraid of that. Currently what I've got is the output is directed to a file for each command, then catted together. I was hoping to be able do this within RAM, since the two commands themselves are a bit I/O heavy.

You have any clue (or someone else) on a good method to have something held within a pipe or something, since I'm really hoping to have to avoid doing this all in C (which I would have to learn to do, as well. Guess its about time I learned...), I'd like to know if I'm looking for the impossible.
# 4  
Old 08-13-2007
Quote:
Originally Posted by forgottenwizard
then catted together
Then why not have the commands write to stdout, then run one command then the other?
# 5  
Old 08-14-2007
Are you refering to something likle

program > $somefile
$format_cmd >> $somefile
program2 >> $somefile

or something else? The reason I have these programs running side-by-side is the length of time (well, actually, its only ~20+ seconds when they run one after the other, but doing it how I have now has that down to ~14 seconds), and I'm hoping to be able to avoid that, plus this would be something nice to know for later on.

What about storing the output in a variable, then echo/cating that into the last file? Granted the output is a bit lengthy, and it could cause some problems, but would that be possible?
# 6  
Old 09-24-2007
Possibilities:

Hey, I'm doing similarly heavy neccessary I/O operations

the thing with putting it into a variable, is you lose the carriage returns. Thats the only problem I can see, it's a bit messy too. You could substitute carriage returns with an unused character such as (¬) and translate them later,.

i.e filevarsub=$(echo $somefiledata | tr -t "\n" "¬")

then bring it back to write to the final file output

echo $filevarsub | tr -t "¬" "\n"

simple, but inelegant.

secondly, you could mount a ramdisk,

mkdir ram # in your main scripts directory
sudo mount -t ramfs /dev/ram ram #there are no options for ram, so umask etc doesnt work
sudo chown $USER ram #i$USER is who you're logged in as

you could stick it /etc/fstab to automount on boot just for your scripts,
or you could fix it so that mounting doesn't require root permissions (be careful with that one), so you can mount from within the scripts

I'd love for there to be a better way, if anyone knows please do tell
# 7  
Old 09-24-2007
Quote:
Originally Posted by forgottenwizard
Are you refering to something likle

program > $somefile
$format_cmd >> $somefile
program2 >> $somefile

or something else?
Something else....

Code:
run_all()
{
     program
     $format_cmd
     program2
}

run_all >output

would concatenate the outputs into "output" without temporary files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Writing Hbase and pig scripts in the bash script file

Hi, I have a script file where i'm validatig the input file and storing the validated records on HDFS. I wanted to load data from HDFS to HBASE using pig script. So for that i have created a HBASE table and written pig script to load data from HDFS to HBASE which is working fine. Now i wanted... (0 Replies)
Discussion started by: shree11
0 Replies

2. Shell Programming and Scripting

Writing hive scripts in bash script file

Hi, I wanted to load data from HDFS to HIVE by writing bash script. Description: I have written a bash script to validate the data and loaded validated data from local file system to HDFS. Now in the same bash script i wanted to load the data from HDFS to HIVE. How can i do it ? Also how tyhe... (2 Replies)
Discussion started by: shree11
2 Replies

3. Shell Programming and Scripting

Question about writing a bash script

Hello, I want to write a bash script to delete the content after '#'. However, if '#' appears in a string with "", ignore this. For example, input file: test #delete "test #not delete" Output file: test "test #not delete" Does anyone know how to write this script? Thanks (1 Reply)
Discussion started by: jeffwang66
1 Replies

4. Shell Programming and Scripting

Mkbootfs writing to stdout in bash script

Hi, I need to automate some repacking tasks of a boot image for Android When in command line, I can use this command: mkbootfs /path/to/root > /path/to/ramdisk-recovery.cpio;However, if I try to run the command from a shell script under Ubuntu, it fails and outputs to stdout instead of the... (27 Replies)
Discussion started by: Phil3759
27 Replies

5. Shell Programming and Scripting

Writing a bash script using host

Im trying to write a script using the host command but its not working properly. I cant understand what Im doing wrong. When I use it at the command prompt, it works fine. But its being used actually in the script, it says its not found: 2 SERVFAIL. Can anyone help me? Here's what I have so far: no... (6 Replies)
Discussion started by: relsha
6 Replies

6. Homework & Coursework Questions

brand new user!.. Lost on BASH script writing

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have just gotten into writing bash scripts for a class, part of the assignment is to read and be able to tell... (4 Replies)
Discussion started by: Byrang
4 Replies

7. Shell Programming and Scripting

Help with writing simple bash script

I want to write a bash script to: 1. Send an email from localhost to an external gmail account. (gmail then automatically forwards the message back to a pop account on the same server. 2. Script waits 3 minutes then checks to see if the email arrived, and if not, it sends an email to... (9 Replies)
Discussion started by: sallyanne
9 Replies

8. Red Hat

red hat Linux 5.0 is detecting 3gb ram but physical ram is 16gb

Hi, On server 64bit Hw Arch , Linux 5.0(32bit) is installed it is showing only 3gb of ram though physical is 16gb can u give me idea why? (4 Replies)
Discussion started by: manoj.solaris
4 Replies

9. Shell Programming and Scripting

Writing Bash script

Could anyone help me to Write a script in BASH Shell to determine the percentage of system disk space you are using. (1 Reply)
Discussion started by: boris
1 Replies

10. Shell Programming and Scripting

Problems writing bash script to unzip files

I'm getting the following errors when I try to write a script to unzip some zip files. When I use the free trial copy of the commerical winzip program, however, they work fine. When I use -l or -t on unzip it indicates no errors. When I use the -o switch interactively from the bash command line it... (1 Reply)
Discussion started by: siegfried
1 Replies
Login or Register to Ask a Question