Hello,
I have a similar problem so I continue this thread.
I have:
my_script_to_format_nicely_bdf.sh | grep "RawData" |tr -s ' '|cut -d' ' -f 4|tr -d '%'
So it supposed to return the percentage used of RawData FS:
80
(Want to use it in a alert script)
However I also have a RawData2 FS so it will output both:
80
60
So in the grep part how can I declare that there is no character after RawData like RawData2?
Thanks in advance
zaxxon
April 21, 2011, 7:45am
2
Easiest would be to post the unfiltered output of your script.
Sorry for hijacking. I thought it will be better to continue as it is a similar case.
What do you mean unfiltered output?
---------- Post updated at 02:51 PM ---------- Previous update was at 02:48 PM ----------
./bdf_rep.sh | grep "RawData" |tr -s ' '|tr -d '%'
138048 122619 15429.5 89 /RawData
193632 116719 76399.9 60 /RawData2
So i need only to display the first line how do I filter this out with grep ?
Does not work cause the output of df is messy ( due to long FS names)
Try this
./bdf_rep.sh | grep "RawData$"
regards,
Ahamed
ctsgnb
April 21, 2011, 8:17am
7
try :
df -k | cat | grep [890][0-9][%]
---------- Post updated at 02:17 PM ---------- Previous update was at 02:17 PM ----------
could you post an example of output of
./bdf_rep.sh
zaxxon
April 21, 2011, 8:21am
8
With unfiltered output I mean to post with using code tags the output of your script my_script_to_format_nicely_bdf.sh
or ./bdf_rep.sh
, so we can maybe easier spot the problem.
No output
./bdf_rep.sh
TOTAL SIZE (MB) USED (MB) FREE (MB) USAGE FILESYSTEM
138048 116729 21319.5 85% /RawData
9000 2774.99 6179.58 31% /var
193632 116719 76399.8 60% /RawData2
780.68 52.4531 650.156 7% /stand
.
.
.
Don't let bdf confuse you
I just need the expression to grep RawData but not RawData2 and problem solved
zaxxon
April 21, 2011, 8:36am
10
./bdf_rep.sh| awk '$NF ~ /RawData$/ {sub(/%/,"",$4); print $4}'
Had to edit, had an error in it.
./bdf_rep.sh | nawk '$NF ~ "RawData$" {print $(NF-1)+0}'
1 Like
drbiloukos:
Nope
"Nope" is not a helpful feedback. Expect the same level of help.....
1 Like
No ouput from zaxxon
Works for vgersh99 (with awk. nawk N/A)
---------- Post updated at 03:44 PM ---------- Previous update was at 03:41 PM ----------
So if I include my bdf_rep script, complete commands is:
#!/usr/bin/sh
bdf |sed -e 's/^\/[^ ]* //' -e 's/^[ \t]*//' | grep -v -e "Filesystem" -e /dev |tr -s ' ' | awk '{printf("%-22s%-12s%-12s%-10s%-20s\n",$1/1024,$2/1024,$3/1024
,$4,$5,$6)}' | sort -n -r -k 4 | awk '$NF ~ "RawData$" {print $(NF-1)+0}'
zaxxon
April 21, 2011, 8:59am
16
Just for completeness, it works for me:
$> cat infile
TOTAL SIZE (MB) USED (MB) FREE (MB) USAGE FILESYSTEM
138048 116729 21319.5 85% /RawData
9000 2774.99 6179.58 31% /var
193632 116719 76399.8 60% /RawData2
780.68 52.4531 650.156 7% /stand
$> awk '$NF ~ /RawData$/ {sub(/%/,"",$4); print $4}' infile
85
Anyhow, you got a solution from vgersh99.
drbiloukos:
No ouput from zaxxon
Works for vgersh99 (with awk. nawk N/A)
---------- Post updated at 03:44 PM ---------- Previous update was at 03:41 PM ----------
So if I include my bdf_rep script, complete commands is:
#!/usr/bin/sh
bdf |sed -e 's/^\/[^ ]* //' -e 's/^[ \t]*//' | grep -v -e "Filesystem" -e /dev |tr -s ' ' | awk '{printf("%-22s%-12s%-12s%-10s%-20s\n",$1/1024,$2/1024,$3/1024
,$4,$5,$6)}' | sort -n -r -k 4 | awk '$NF ~ "RawData$" {print $(NF-1)+0}'
most likely you don't need so many piped filters. What you're after can easily be done with a single awk (saving on CPU and the confusion).
ctsgnb
April 21, 2011, 10:04am
18
Display FS whose theshold exceed or equal 80
$ ./bdf_rep.sh | awk '$4+0>=80{print$5,$4+0}'
/RawData 85
/RawData2 100
/stand 95
$ ./bdf_rep.sh | awk '$4+0>=80{print$5,$4}' mdf
/RawData 85%
/RawData2 100%
/stand 95%
$ ./bdf_rep.sh | awk '$4+0>=80{print$5}' mdf
/RawData
/RawData2
/stand