web-dev-qa-db-ja.com

「service foo status」が「less」を介して出力をページングしないようにできますか?

コマンドservice <name> statusがその出力でlessを使用しないようにするにはどうすればよいですか?

いくつかのsysadminアクションを自動化するスクリプトがあり、サーバーをUbuntu 16.04にアップグレードした後、サービスステータスをチェックするアクションがlessのようなものを使用して出力、特にsupervisorサービス。

実行するように構成されたいくつかのデーモンがあり、Sudo service supervisor statusを実行すると、次のようになります。

* supervisor.service - Supervisor process control system for UNIX
   Loaded: loaded (/lib/systemd/system/supervisor.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2017-02-06 20:35:34 EST; 12h ago
     Docs: http://supervisord.org
  Process: 18476 ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown (code=exited, status=0/SUCCESS)
 Main PID: 20228 (supervisord)
   CGroup: /system.slice/supervisor.service
           |- 7387 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7388 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7389 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7390 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7391 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7392 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7393 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7394 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7395 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7396 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7397 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7398 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7678 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7679 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7680 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7681 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7682 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7683 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7684 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7685 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7693 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7694 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7698 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7702 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7703 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7705 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7707 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7709 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7710 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7712 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7713 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7717 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7720 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7723 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7724 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7728 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7730 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7731 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7733 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7734 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7735 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7738 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7743 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7747 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7748 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7750 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7752 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7756 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7758 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7761 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7763 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7764 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7772 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7781 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7785 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7794 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7799 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7801 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
           |- 7805 /usr/local//myproject/.env/bin/python2.7 /usr/local//myproject/.env/bin/celery worker -A /myproject -l info --autoreload
lines 1-66

そして、手動で下にスクロールするか押すまでは戻りません Q 出る。この機能を無効にするにはどうすればよいですか?

37
Cerin

Ubuntuはsystemdシステムであり、service statusコマンドは実際にsystemctl statusを呼び出します。systemctlには、目的の機能を実行する--no-pagerオプションがあります。したがって、スクリプトで直接systemctlコマンドを使用する方がよい場合があります。

Sudo systemctl --no-pager status supervisor

編集:env var SYSTEMD_PAGER

@jwodderで指摘されている別の方法は、SYSTEMD_PAGER環境変数を設定することです。これには、systemctlなどの別のアプリケーションから呼び出されたときにserviceの出力にも影響を与えるという追加の利点があります。

export SYSTEMD_PAGER=''
Sudo service supervisor status

同じ出力を実現できます。

58
Tim Kennedy

lessは、その出力が端末でないことを検出した場合、通常はページャーモードをオフにします。したがって、次のようなコマンドを実行して、コマンドの出力を非端末にすることができます。

Sudo service supervisor status | cat
36
dhag

から man systemctl

ENVIRONMENT
...
   $SYSTEMD_PAGER
       Pager to use when --no-pager is not given; overrides $PAGER.
       Setting this to an empty string or the value "cat" is equivalent to
       passing --no-pager.

   $SYSTEMD_LESS
       Override the default options passed to less ("FRSXMK").

したがって、環境の初期化のどこかに、次のように設定します。

SYSTEMD_PAGER=
16
muru

sudoersファイルも変更する必要があります。

 Defaults        env_keep += "SYSTEMD_PAGER"
3
JalapenoGremlin