Afficher un message
Vieux 05/11/2006, 18h44   #3
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: execute command inside awk

2006-11-5, 09:06(-08), relikwie:
> Hi, below a code snippet that checks filesize and reports on this.
>
> ls -Ll /${FILE} | awk '{ if($5 < 1610612736)
> print $9,"Less than 1.5 Gbytes",$5 ;
> else print $9,"GREATER than 1.5 Gbytes - ",$5 }'
> } > result.txt
>
> How can I log the output and set a parameter if size > 1.5Gb, so I can
> take further action in the script.
> Mail a warning.

[...]


Let awk's exit status reflect whether the condition is met or
not:

if
ls -dLl "/${FILE}" | awk '
{
if ($5 < 1.5 * 1024 * 1024 * 1024) {
print $9,"Less than 1.5 Gbytes",$5 ;
exit(0)
} else {
print $9,"GREATER than 1.5 Gbytes - ",$5
exit(1)
}
}' > result.txt
then
action if less than 1.5 GB
else
action if at least 1.5 GB
fi

--
Stéphane
  Réponse avec citation
 
Page generated in 0,06173 seconds with 9 queries