/etc/profileのコマンドを見つける方法は? [コピー]

/etc/profileのコマンドを見つける方法は? [コピー]

オペレーティングシステム:debian9。

touch /home/test/test.log

/etc/profileに単純なwrite-date関数があります。

write-date(){
    date >>  /home/test/test.log
    }

再起動または終了時に実行されるサービスを作成します。

vim  /etc/systemd/system/test.service  

[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash  /home/test/test.sh

[Install]
WantedBy=multi-user.target

/home/test/test.sh の簡単な機能書き込み日。

vim  /home/test/test.sh
write-date

テストサービスを有効にします。

sudo systemctl enable test.service

コンピュータを再起動し、test.service ログを確認しました。

sudo journalctl -u test
-- Logs begin at Thu 2018-02-01 00:03:59 HKT, end at Thu 2018-02-01 00:15:54 HKT. --
Feb 01 00:04:04 test systemd[1]: Starting Run command at shutdown...
Feb 01 00:04:05 test bash[438]: /home/test/test.sh: line 3: write-date: command not found
Feb 01 00:04:11 test systemd[1]: test.service: Main process exited, code=exited, status=127/n/a
Feb 01 00:04:11 test systemd[1]: Failed to start Run command at shutdown.
Feb 01 00:04:11 test systemd[1]: test.service: Unit entered failed state.
Feb 01 00:04:11 test systemd[1]: test.service: Failed with result 'exit-code'.

/etc/profileのコマンドを見つける方法は?

cat -vet /home/test/test.sh
$
$
    write-date$
    $
$

ベストアンサー1

ソースが必要であることをサービスに明示的に知らせる必要があるかもしれません/etc/profile

[Unit]
Description=Run command at shutdown
Before=shutdown.target reboot.target

[Service]
EnvironmentFile=-/etc/profile
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/bash  /home/test/test.sh

[Install]
WantedBy=multi-user.target

この行に注意してくださいEnvironmentFile

おすすめ記事