skip to Main Content

I am not able to run reboot commands on my CentOS 7 machine.
For example I’ve created a script: /home/usr/myscript.sh (marked executable) with:

echo "hello world" > example.txt

When Im trying to run the script from terminal everything works good.
I tried to start the script on reboot at the end of the file:
nano /etc/crontab
I added:
@reboot /home/usr/myscript.sh

and on restart, nothing happen.
I also tried to edit file:
crontab -e
its looks like a new generated file, I’ve typed my command, and again nothing happend.
How can I run a command on CentOS at reboot?
I tried to insert that command on my Ubuntu machine, and everything was good and worked properly.

Anyone can advise on different way (maybe 3rd party program) that will help me to manage the reboot jobs?
Thanks for the help.
BTW, its might be duplicate, but I cant find any answer that helped me

2

Answers


  1. Chosen as BEST ANSWER

    I was able to reach this out by adding a crontab file for my user. with the following command: crontab -u usrname filename That allow me to run my scripts. Thanks !


  2. In CentOS/RHEL 7, the systemctl utility replaces some older power management commands used in previous versions. The table below compares the older and new equivalent systemctl commands. The old commands listed in the table still exist for compatibility reasons.

    Older Command       systemctl equivalent           Description

    halt                     systemctl halt              Halts the system
    poweroff              systemctl poweroff        Powers off the system
    reboot                 systemctl reboot             Restarts the system
    pm-suspend         systemctl suspend          Suspends the system
    pm-hibernate         systemctl hibernate          Hibernates the system
    pm-suspend-hybrid     systemctl hybrid-sleep      Hibernates and suspends the system

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search