[CentOS] Running a command at startup

Simon Matter simon.matter at invoca.ch
Thu Dec 13 15:28:07 UTC 2018


>
>
> On 12/13/18 8:17 AM, Jonathan Billings wrote:
>> On Wed, Dec 12, 2018 at 09:43:56PM -0500, Robert Moskowitz wrote:
>>> OK....
>>>
>>> I have had problems in the past with crontab parsing a command. Would I
>>> use:
>>>
>>> @reboot root echo none | tee /sys/class/leds/blue\:heartbeat/trigger
>>>
>>> ?
>>>
>>> Or do I have to make a script and run that?
>> Since this is a crontab, you can use normal shell redirection:
>>
>> @reboot root echo none > /sys/class/leds/blue\:heartbeat/trigger
>>
>> in a file in /etc/cron.d/
>>
>> The 'echo foo | sudo tee' thing is what you do for people who are
>> using sudo to echo output into a file -- so often people think they
>> can do 'sudo echo none > /some/path' and will be surprised it doesn't
>> work.
>
> Thanks.  This is my first encounter with 'tee'.  I guess because I
> rarely use sudo, and work in su if I need to do root things.
>
>> I still think it makes sense to create it as a systemd unit.
>>
> Seems the better, long-term way to go, but right now I don't have time
> to learn enough about making systemd unit files.

But I think even the rc.local hack should work if you make it executable.
At least that's what the header of rc.local says.

Regards,
Simon




More information about the CentOS mailing list