
リモートで ssh を使用してディスク領域を抽出するために次のコマンドを使用しています。ただし、以下のように他のすべてのメッセージではなく、出力のみを保存したいと考えています。
何か助けはありますか?または代替の解決策はありますか?
ssh rajesh-server 'df -h /db* | cat' 2>&1
|-----------------------------------------------------------------|
| This system is for the use of authorized users only. |
| Individuals using this computer system without authority, or in |
| excess of their authority, are subject to having all of their |
| activities on this system monitored and recorded by system |
| personnel. |
| |
| In the course of monitoring individuals improperly using this |
| system, or in the course of system maintenance, the activities |
| of authorized users may also be monitored. |
| |
| Anyone using this system expressly consents to such monitoring |
| and is advised that if such monitoring reveals possible |
| evidence of criminal activity, system personnel may provide the |
| evidence of such monitoring to law enforcement officials. |
|-----------------------------------------------------------------|
Filesystem Size Used Avail Use% Mounted on
/dev/vx/dsk/xcv01_day/db01_day
200G 154G 44G 79% /db01_day
/dev/vx/dsk/xcvg01_day/db01_day
200G 154G 44G 79% /db01_day
/dev/vx/dsk/xcvg01_day/db01_day
200G 154G 44G 79% /db01_day
答え1
「ボックス」内のすべてのテキストは、コマンドではなく、ログイン スクリプトによって生成されますdf
。多くの場合、ログイン メッセージでセットアップされたサーバーは、ホーム ディレクトリに というファイルが存在する場合、それらのメッセージを表示しません.hushlogin
。まず、そのファイルを作成してみてください。
ssh rajesh-server "touch .hushlogin"
| cat
次に、コマンドラインで や stderr リダイレクトは必要ありません。代わりにこれを試してください:
ssh rajesh-server 'df -h /db*'
ファイルが配置されているにもかかわらずメッセージが引き続き表示される場合は.hushlogin
、出力を解析する必要があります。次のようにします。
ssh rajesh-server 'df -h /db*' | sed '/^|/d'
このsed
コマンドは、ssh コマンドの出力を受け取り、パイプ文字で始まる行を削除し、その他すべてを出力します。
おそらく、この種のタスク専用に構築された監視ツールの使用を検討する必要があることに注意してください。多くのツールが存在し、その中には次のようなものもあります。RRDツールフロントエンド。私のお気に入りはサボテンそしてムニンディスク(またはネットワークなど)の使用状況をグラフ化して、時間の経過に伴う変化を確認できます。
答え2
ssh rajesh-server 'df -h /db*' > file 2> /dev/null
はリモートdf
出力を に送信しfile
、サーバーの cruft を に送信します/dev/null
。