It seems obvious to me that I am missing something here. I have the following:
It's simple enough, running du and using tee to redirect to multiple commands for processing. The function creates a little in-the-moment report so we have an idea of where in the processing we are. The awk 'END' prints out the final value from du (the total).
What I want to do is use the awk 'END' to set a variable ($sizeRAW). I've been exploring many ideas (including a second simple function), but I haven't yet come across a solution. Maybe exec? Named pipe? Great gurus of the BASH, there must be a way.
I suspect you're overthinking this a great deal. Just print your progress to standard error, and the actual data to standard output. stdout will be caught in the variable, stderr will go direct to your console.
You can even do some console-tricks (\r, to go to the beginning of the line, instead of \n, to go to the next line) so its output isn't too spammy.
/dev/stderr is how you tell awk to print to standard error. It has a special meaning to awk (even though some systems do have an actual /dev/stderr these days).
Last edited by Corona688; 10-12-2014 at 04:38 PM..
Perhaps I am overthinking (I can't deny that I do that frequently), however on both Ubuntu and OS X,
gives me a total approximately 8 times as big as expected (probably because it's adding $1 which includes a summary of every folder, a size for every entry within said folders, plus the final total). It also doesn't seem to actually print a path.
So, cleaning up a bit
sort of does what I want, although the output is a bit spazzy. I don't really need the full path, and some of these will be too long for the output anyway.
Ideally, I'd printf() just the root-level folders for the argument, but splitting that out of $2 doesn't seem to work. Again, there's no path printed to the console.
I appreciate the alternate viewpoint. I'll keep exploring it.
Are you just trying to get the total of the top level directories or something? I'm confused to what the overall aim is. If you can explain what you are trying to achieve then perhaps an alternate logic, or just using the -s flag of du might sort you out.
Perhaps I am overthinking (I can't deny that I do that frequently), however on both Ubuntu and OS X,
gives me a total approximately 8 times as big as expected (probably because it's adding $1 which includes a summary of every folder, a size for every entry within said folders, plus the final total). It also doesn't seem to actually print a path.
So, cleaning up a bit
sort of does what I want, although the output is a bit spazzy. I don't really need the full path, and some of these will be too long for the output anyway.
Ideally, I'd printf() just the root-level folders for the argument, but splitting that out of $2 doesn't seem to work. Again, there's no path printed to the console.
I appreciate the alternate viewpoint. I'll keep exploring it.
That's why I had -F, to split the path. Now that I understand that you just want the last line:
What I'm trying to do is display the top level directory as du is grabbing size data from it's contents, and grab the total size of all contents for a variable used later in a script.
For instance, if I run
this "function" would display "var" as it is gather sizes of items in the "var" folder, and at the end of the command run it would grab the total into a variable.
Corona, that still doesn't display anything as it's running. Admittedly, I'm currently on an OS X system (at work on break), but I got the same results (no display of the directories after the "Checking ") when I ran it on Ubuntu 14.04.
I'm on Ubuntu 14.04 and I manually updated my coreutils so that "tee" is now on version 8.27
I was running a script using bash where there is some write to pipe error at some point causing the tee command to exit abruptly while the script continues to run. The newer version of tee seems to prevent... (2 Replies)
i try to find way to make string concatenation in csh ( sorry this is what i have )
so i found out i can't do :
set string_buff = ""
foreach line("`cat $source_dir/$f`")
$string_buff = string_buff $line
end
how can i do string concatenation? (1 Reply)
08:29 < xsi> >{respo,nd}.php bash: {respo,nd}.php: ambiguous redirect
08:31 < geirha> xsi: maybe you want tee
So I was advised to do so. And I can't create two OR MORE files at once with {a,b,c,d,e,f}.php
(which I quickly now need to create and to learn to create in the future to quickly... (2 Replies)
dear all
suppose I have two files file_000 and file_id:
file_000:
blablablabla000blablabla000
000blahblah000blahblah
blah000blahblahfile_id:
001
002
003now, based on file_id, I want to create 3 files; the name of each file would be file_001,file_002,file_003,respectively, and the... (4 Replies)
Dear All,
I am trying to write a Unix Script which fires a sql query. The output of the sql query gives multiple rows. Each row should be saved in a separate Unix File.
The number of rows of sql output can be variable. I am able save all the rows in one file but in separate files.
Any... (14 Replies)
HI,
I would like to create the files as
file1.txt
file2.txt
file3.txt
......
.......
.......
filen.txt
in a single unix command, i dont want to use the loops.
n is user specific
Kindly help me in this.
THank you
Jagadeesh (2 Replies)
why I cannot do this?
prog_name | tee logfile | awk /regexp/ | awk /regexp/ I now this is not elegant code, but am intrigued as to why multiple pipes from tee not allowed. (2 Replies)
Hi All,
How do I create /var as LVM type during install? I want my new OS to have /var as LVM so that I could extend it on the fly.
Thanks for any comment you may add. (2 Replies)
hi sirs
can u tell the difference between /var/log/syslogs and /var/adm/messages
in my working place i am having two servers.
in one servers messages file is empty and syslog file is going on increasing..
and in another servers message file is going on increasing but syslog file is... (2 Replies)