a1_win
August 23, 2011, 3:52am
1
Hi All,
Linux 86x64bits Red Hat Linux O/S
Could someone please check and let me know if the shell script has any syntax error as it's not sending mails
Shell script:
cat dataspace.sh
#!/bin/bash
export DBALIST="xyz@abc.com"
export data_capacity
df -k /oradata > dfk.result
data_capacity=`grep -v File dfk.result | awk -F" " '{ print $4 }' | cut -c 1-3`
if [[ $data_capacity > 30% ]]
then
mailx -s "Filesystem /oradata is ${data_capacity} filled" $DBALIST < dfk.result
fi
Thanks for your time!
Regards,
a1_win
zaxxon
August 23, 2011, 3:57am
2
If you'd had a syntax error, the shell or tools would have told you. Use set -x
as second command after the shebang (#!...) and see if there is some value or condition not met.
echo $data_capacity
if [ "$data_capacity" -gt "30" ]
then
mailx -s "Filesystem /oradata is ${data_capacity} filled" $DBALIST < dfk.result
else
echo "I am in else part"
fi
a1_win
August 23, 2011, 4:52am
4
Hi,
The output is coming as:
Filesystem /oradata is :
39% -> in the next line
The output should have been like:
Filesystem /oradata is:39% filled
Thanks
a1_win
panyam
August 23, 2011, 5:08am
5
Can you please post sample df -k output from your system here. ( the one with /oradata)?
Else simulate the below code for your requirement.
df -k /stand
/stand (/dev/vg00/lvol1 ) : 269032 total allocated Kb
38864 free allocated Kb
230168 used allocated Kb
85 % allocation used
TEST SSYTEM> data_capacity=`df -k /stand | grep -v Kb | awk '{ print $1 }'`
TEST SSYTEM>[ $data_capacity -ge 80 ] && mailx -s "Filesystem /oradata is ${data_capacity}%filled" $DBALIST
a1_win
August 23, 2011, 5:22am
6
dfk.result output:
cat dfk.result
Filesystem 1K-blocks Used Available Use% Mounted on
abc:/vol/xyz_oradata
471859200 180505120 291354080 39% /oradata
size=$(nawk '{disk_size=$4;}END{print substr(disk_size,1,length(disk_size)-1)}' dfk.result) && [ "${size}" -gt "30" ] && mail -s "Filesystem /oradata is ${size} filled" $DBALIST < dfk.result
panyam
August 23, 2011, 5:54am
8
data_capacity=`tail -1 df.k | cut -d" " -f4 | sed 's/%//'`
[ $data_capacity -ge 30 ] && mailx -s "Filesystem /oradata is ${data_capacity}%filled" $DBALIST
a1_win
August 24, 2011, 4:38am
9
Thanks to all for your valuable time!
I have now the output as expected!
Please let me know if there is a shell script which checks all the mounts in the Oracle Db Tier that alerts once the space usage crosses over 75%
Thanks for your time once again!
Regards,
a1_win
---------- Post updated 08-24-11 at 04:38 AM ---------- Previous update was 08-23-11 at 11:55 AM ----------
Continuing from - Disk Monitoring shell script giving incorrect information thread..
Using the code below:
$ df -h | grep % | sed 's,%,,g' | awk ' { if ($5>=30) {print $0} } ' > disk_chk_out
$ mailx -s "Disk Check > 30%" abc@xyz.com < disk_chk_out
Still getting the output which should not be receiving from e-mail alert as the criteria is below 30%:
/dev/sda1 99M 21M 74M 22 /boot
tmpfs 9.8G 28M 9.8G 1 /dev/shm
E-mail alert output as below:
Filesystem Size Used Avail Use Mounted on
/dev/sda3 20G 13G 6.2G 68 /
/dev/sda1 99M 21M 74M 22 /boot
400G 272G 129G 68 /oradata
1.2T 526G 691G 44 /orabkup
2.3T 1.6T 728G 69 /software
2.3T 1.6T 728G 69 /backup
2.3T 1.6T 728G 69 /patches
450G 170G 281G 38 /xyz_oradata
150G 67G 84G 45 /orabin
225G 106G 120G 48 /oradata_TEST
tmpfs 9.8G 28M 9.8G 1 /dev/shm
40G 20G 21G 48 /abc_orabin
Now what's wrong here
Thanks,
a1_win
panyam
August 24, 2011, 5:17am
10
Use below awk:
awk 'NF==5&&$4>30||NF==6&&$5>30'
If it does not help. Post df -h output here.
a1_win
August 24, 2011, 6:07am
11
Hi Panyam,
Thanks but that didn't help either
df -h output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 20G 13G 6.2G 68% /
/dev/sda1 99M 21M 74M 22% /boot
fcsan02:/vol/xxx_oradata
400G 272G 129G 68% /oradata
fcnas01:/vol/oraclebackups/xxx
1.1T 526G 578G 48% /orabkup
fcnas01:/vol/ebs/software
2.3T 1.6T 728G 69% /software
fcnas01:/vol/ebs/backup
2.3T 1.6T 728G 69% /backup
fcnas01:/vol/ebs/patches
2.3T 1.6T 728G 69% /patches
fcsan03:/vol/xxx_xxoradata
450G 170G 281G 38% /xyz_oradata
fcsan03:/vol/xxx_scripttest
20G 96K 20G 1% /scripttest
fcsan03:/vol/orabin/xxx
150G 67G 84G 45% /orabin
fcsan01:/vol/ebs/eptp51
10G 5.5M 10G 1% /ebs/eptp51
fcsan02:/vol/SnapManager_20101206155612743_xxx_oradata
225G 106G 120G 48% /oradata_xxx
tmpfs 9.8G 28M 9.8G 1% /dev/shm
fcsan03:/vol/xxx_oraerp
40G 20G 21G 48% /orabin
fcsan03:/vol/xxx_archerp
40G 1.4G 39G 4% /oradata2
Regards,
a1_win
Try out the below one, and let us know, is the one you need as a email ?
df -h | awk '/%/ {a=substr($(NF-1),1,length($(NF-1))-1); if(a>30){print $0}}'
zaxxon
August 24, 2011, 6:26am
13
@ a1_win:
Since you ignore PMs and moderator notes I want to make you think about, that if you continue to ignore to use code tags, you collect infraction points which will result in a permanent ban after collecting an amount of them. So maybe consider reading your PMs and use code tags.
See (B) in this link if you do not understand how to use them:
The UNIX and Linux Forums - Forum Rules
a1_win
August 24, 2011, 6:39am
14
Hi,
Still I am getting the below output in e-mail alert which is below 30% criteria:
40G 1.4G 39G 4% /oradata2
I used the code tag as above but didn't help.
df -h | awk '/%/ {a=substr($(NF-1),1,length($(NF-1))-1); if(a>30){print $0}}'
Thanks,
a1_win
---------- Post updated at 06:39 AM ---------- Previous update was at 06:35 AM ----------
Sure Zaxxon, will start using the code tags by typing as Code Tag which I juts did in the last post
Thanks for the information
code tag means
your data
---------- Post updated at 04:18 PM ---------- Previous update was at 04:16 PM ----------
Strange, why it is taking 4 as greater than 30
still checking...
$ nawk '/%/ {a=substr($(NF-1),1,length($(NF-1))-1); if(a > 30){print $0}}' test
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 20G 13G 6.2G 68% /
400G 272G 129G 68% /oradata
1.1T 526G 578G 48% /orabkup
2.3T 1.6T 728G 69% /software
2.3T 1.6T 728G 69% /backup
2.3T 1.6T 728G 69% /patches
450G 170G 281G 38% /xyz_oradata
150G 67G 84G 45% /orabin
225G 106G 120G 48% /oradata_xxx
40G 20G 21G 48% /orabin
40G 1.4G 39G 4% /oradata2
bash-3.00$ cat test
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 20G 13G 6.2G 68% /
/dev/sda1 99M 21M 74M 22% /boot
fcsan02:/vol/xxx_oradata
400G 272G 129G 68% /oradata
fcnas01:/vol/oraclebackups/xxx
1.1T 526G 578G 48% /orabkup
fcnas01:/vol/ebs/software
2.3T 1.6T 728G 69% /software
fcnas01:/vol/ebs/backup
2.3T 1.6T 728G 69% /backup
fcnas01:/vol/ebs/patches
2.3T 1.6T 728G 69% /patches
fcsan03:/vol/xxx_xxoradata
450G 170G 281G 38% /xyz_oradata
fcsan03:/vol/xxx_scripttest
20G 96K 20G 1% /scripttest
fcsan03:/vol/orabin/xxx
150G 67G 84G 45% /orabin
fcsan01:/vol/ebs/eptp51
10G 5.5M 10G 1% /ebs/eptp51
fcsan02:/vol/SnapManager_20101206155612743_xxx_oradata
225G 106G 120G 48% /oradata_xxx
tmpfs 9.8G 28M 9.8G 1% /dev/shm
fcsan03:/vol/xxx_oraerp
40G 20G 21G 48% /orabin
fcsan03:/vol/xxx_archerp
40G 1.4G 39G 4% /oradata2
panyam
August 24, 2011, 6:55am
16
This should solve the problem:
TEST_SYSTEM>df -h | awk '/%/ {$0=(a?a" "$0:$0);a="";gsub("%","");print $0;next} {a=$0;next}' | awk '$5>30' > disk_chk_out
TEST_SYSTEM>mailx -s "Disk Check > 30%" abc@xyz.com < disk_chk_out
substr is the issue..
try this.
$ df -h | nawk '/%/ {if(length($(NF-1))> 2) {a=substr($(NF-1),1,length($(NF-1))-1); if(a > 30){print $0}}}'
a1_win
August 25, 2011, 12:38am
18
Many thanks to all of you for your time to help resolve this issue now!
itkamaraj: Thanks so much for your time. Yes now it's working fine as per the expected output
itkamaraj: Could you please explain me the code used as below:
Code Tag:
$ df -h | nawk '/%/ {if(length($(NF-1))> 2) {a=substr($(NF-1),1,length($(NF-1))-1); if(a > 30){print $0}}}'
Thanks,
a1_win
nawk '/%/ {if(length($(NF-1))> 2) {a=substr($(NF-1),1,length($(NF-1))-1); if(a > 30){print $0}}}'
/%/ --> Match % and process the lines which is having %
$(NF-1) --> Print the value of (last - 1) column value (disk usage column)
length($(NF-1)) --> Get the length of the disk usage column.
if(length($(NF-1))> 2 --> check the length is greater than 2 ( It will eliminate the usage which is less than 10%)
a=substr($(NF-1),1,length($(NF-1))-1); --> Strip the % value from the disk usage column ( eg: 85% to 85 )
then check a > 30, then print the line.
More example for understaing :
echo "abc edf ghi" | awk '{ print $NF }' # prints the last record value
echo "abc edf ghi" | awk '{ print $(NF-1) }' # prints the last-1 record value
echo "abc edf ghi" | awk '{ print $(NF-2) }' # prints the last-2 record value
echo "abcd efg hi" | awk '{print length($1)}' # prints the lenght of first record
echo "abcd efg hi" | awk '{print length($2)}' # prints the lenght of second record
echo "abcd efg hi" | awk '{print length($3)}' # prints the lenght of third record
echo "abcdefg" | awk '{ print substr($0,1,2)}' # prints 2 letters from the 1st position