複数のコマンドを使用するawkコマンド

複数のコマンドを使用するawkコマンド

以下のコードを試してみると、次のエラーが発生します。

+ awk '{if ($1 > 1) 
{ print "Memory utilisation is high \n Please find history of the memory utilisation below" 
sar -r|awk {print' ',,,}| column -t } 
 }'
awk: cmd. line:2: sar -r|awk {print
awk: cmd. line:2:        ^ syntax error
awk: cmd. line:3: sar -r|awk {print

top -M -n1 | grep "Mem" | awk '{print 0 + $7}' | awk '{ print $1 / 1024 }' | awk '{if ($1 > 1)
{ print "Memory utilisation is high \n Please find history of the memory utilisation below"
sar -r|awk '{print $1,$2,$3,$4}'| column -t }
 }' >>/home/shyam/utilisation.txt

両方の出力をファイルにリダイレクトするにはどうすればよいですか?

ベストアンサー1

一般的に不要grep .. | awk ..| awk

私は変わるgrep "Mem" | awk '{print 0 + $7}' | awk '{ print $1 / 1024 }'

  • 到着awk '/Mem/ {print 0 + $7}' | awk '{ print $1 / 1024 }'
  • 到着awk '/Mem/ {print 0 + $7/1024 }'
  • 到着awk '/Mem/ { if ( $7 > 1024 ) ...

から始めます

top -M -n1 | awk '/Mem/ {if ($7 > 1024) { 
      print "Memory utilisation is high \n" ;
      print "Please find history of the memory utilisation below\n" ;
      print " sar -r|awk \'{print $1,$2,$3,$4}\'| column -t \" } }' >>/home/shyam/utilisation.txt

おすすめ記事