inittabでスクリプトを実行する前に、環境変数を設定してください。

inittabでスクリプトを実行する前に、環境変数を設定してください。

inittabには次の項目があります。

scpt:234:once:RSYNC_OPTIONS=-q /path/to/script/script.sh arg1 arg2 arg3 2>&1

ただし、実際に実行しようとしたため失敗しますRSYNC_OPTIONS=-q

scpt:234:once:export RSYNC_OPTIONS=-q;/path/to/script/script.sh arg1 arg2 arg3 2>&1

しかし、これも失敗した。これを行う方法はありますか?それともスクリプトを変更する必要がありますか?

ベストアンサー1

Linux sysvinit実装のソースコードを見ると、シェル特殊文字を見るとシェルを実行しますが、文字列のexec前に特殊文字を追加するので、リダイレクトを入れて引数に特殊文字を使用できますが、環境変数は次のとおりです。

  } else if (strpbrk(proc, "~`!$^&*()=|\\{}[];\"'<>?")) {
  /* See if we need to fire off a shell for this command */
        /* Give command line to shell */
        args[1] = SHELL;
        args[2] = "-c";
        strcpy(buf, "exec ");
        strncat(buf, proc, sizeof(buf) - strlen(buf) - 1);
        args[3] = buf;
        args[4] = NULL;

簡単な解決策はを実行することですenv

scpt:234:once:env RSYNC_OPTIONS=-q /path/to/script/script.sh arg1 arg2 arg3 2>&1

任意のコマンドを実行する方法のいくつかの考えられる解決策は次のとおりです。

scpt:234:once:>&1; RSYNC_OPTIONS=-q exec /path/to/script/script.sh arg1 arg2 arg3 2>&1
scpt:234:once:2>&1; RSYNC_OPTIONS=-q exec /path/to/script/script.sh arg1 arg2 arg3

おすすめ記事