df command for listing 90% + dirs and hostname condition

 df -k | grep -v  dcs |grep -v Filesystem| awk -F" " '{if(substr($5,0,length($5)-1)>87)print $5" " $6}' >> sms.txt 

1) Is it the correct way to list all the filesystems > 90%
2) Is there any way to print hostname in this command ? The hostname should get printed in sms.txt file only when there exists filesystems > 90%.
If there is no file system > 90 % hostname should NOT get printed in sms.txt file.

try this.

 
h=$(hostname);df -k | awk -v h="$h" '!/dcs/ && NR>1 {if(substr($5,0,length($5)-1)>87)print h" "$5" " $6}' >> sms.txt
1 Like

thanks itkamaraj but i am getting

awk: syntax error near line 1
awk: bailing out near line 1

can you post the command you tried.

1 Like

Hi itkamaraj,
I tried following
1.typing following command at command prompt

 h=$(hostname);df -k | awk -v h="$h" '!/dcs/ && NR>1 {if(substr($5,0,length($5)-1)>87)print h" "$5" " $6}' >> sms.txt 

2.same command in sh script file.
3.same command in bash script file.

I also tried changing h=$(hostname) to h=`hostname` but I am getting same error in all above cases..
error
awk: syntax error near line 1
awk: bailing out near line 1

FYI I am using Solaris
uname -v
Generic_122300-60

Thanks,
Ajay

use nawk instead of awk

1 Like

Thanks itkamaraj this is working but when i connect to the another server using ssh then hostname it takes is actually previous server ...
e.g.

ssh userid@servername
h=`hostname`;df -k | nawk -v h="$h" '!/dcs/ && NR>1 {if(substr($5,0,length($5)-1)>88)print h" "$5" " $6}' >> sms.txt

Above code should display servername in the ssh command but it is displaying the servename from where i am running this script.

Please advise.
Thanks,
Ajay

Use backslashes ..

$ ssh user@servername "a=\$(hostname); echo \$a"
servername
$
1 Like

getting error sh: syntax error at line 1: `a=$' unexpected

try this...

 
ssh user@servername 'a=5; echo "value of $a"'

why dont you put the script in the destination server and invoke it from the ssh ?

ssh user@server "sh /path/of/remote/server/script.sh"