我写了这个单元():/etc/systemd/system/[email protected]
[Unit]
Description=TEST (%I)
[Service]
ExecStart=/bin/echo "%i %I" >> /home/vagrant/test.txt
[Install]
WantedBy=multi-user.target
在我运行systemctl enable test@
和后systemctl start 'test@slug=test phone=999999999999'
,我在 上看不到任何文件/home/vagrant
。
的输出systemctl status 'test@slug=test phone=999999999999'
是:
● test@slug\x3dtest\x20phone\x3d99999999999.service - TEST (slug=test phone=99999999999)
Loaded: loaded (/etc/systemd/system/[email protected]; disabled; vendor preset: enabled)
Active: inactive (dead)
May 01 15:40:51 vagrant-ubuntu-wily-32 systemd[1]: Started TEST (slug=test phone=99999999999).
May 01 15:40:51 vagrant-ubuntu-wily-32 echo[2161]: slug\x3dtest\x20phone\x3d99999999999 slug=test phone=99999999999 >> /home/vagrant/test.txt
我尝试使用来检查语法错误,但输出是:。systemd-analyze verify [email protected]
Failed to load [email protected]: Invalid argument
答案1
您不能>>
在ExecStart
.您需要让它运行一个可以为您执行重定向的 shell,或者设置StandardOutput=
.例如,尝试
ExecStart=/bin/bash -c 'echo "%i %I" >> /home/vagrant/test.txt'