0
sudo nano /etc/rc.local

I have run the above and added the path below. HDD_temp is an executable text file.

/home/matthew/@/HDD_temp/HDD_temp

However, the file is not run at system startups. How can I run it at system startups?

2

You can also make a systemd "service". For example:

Create an empty text file using vi, nano or whatever:

[Unit]
Description=My service
[Service]
ExecStart=/path/to/my/script.sh
ExecStop=/usr/bin/killall script.sh

# Useful during debugging; remove it once the service is working
StandardOutput=console

[Install]
WantedBy=multi-user.target

Save it under /etc/systemd/system/myscript.service or any other name,

Then run:

sudo systemctl start myscript

You can check the service with sudo systemctl status myscript and stop with sudo systemctl stop myscript. To make it starts after boot run systemctl enable myscript as root.

  • Thanks a lot! I successfully ran "sudo systemctl enable testing.service", which I don't need anymore. How can I disable the service and delete the "symlink" previously created? I have already deleted the "testing.service" file. – Matthew Wai Mar 6 at 0:10
2

You can use cron and and the script to be run at @reboot.

To edit: sudo crontab -e.

Then add the task:

@reboot the_script_to_be_run
  • When I ran "sudo crontab -e", I was given three options. I selected " 1. /bin/nano <---- easiest". Did I select the right one? – Matthew Wai Mar 1 at 19:16
  • @MatthewWai If you like the easiest, then I guess so. – Tomasz Mar 1 at 19:17
  • I need to run a service file. Can I add this: "@reboot /lib/systemd/system/fancontrol-via-hddtemp.service"? – Matthew Wai Mar 2 at 7:09
  • 1
    @MatthewWai No, a Systemd service is not supposed to be run this way. – Tomasz Mar 2 at 7:39
  • The command "sudo service fancontrol restart" needs to be run 30 seconds after the script file "HDD_temp" (not a Systemd service) is run at system startups. What task should be added into Crontab? – Matthew Wai Mar 2 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.