[tool] Ubuntu, Win10 settings to start python script on boot

Foreword:

By the way, every time I set up the server and turn it on again, the IP will change accordingly. Fixed IP is sometimes difficult to use. So why not let me send the ip to me every time I start it.

step:

sudo touch /etc/rc.local
sudo chmod 777 /etc/rc.local
sudo systemctl enable rc-local.service
vim /etc/rc.local 
#编写脚本
    #!/bin/bash -e 
    /bin/su - username -c "/home/username/start.sh"
        #nohup python3 /home/xxxxx/.py >./log.log 2>&1&

    echo start xx.py
    exit 0
    

sudo systemctl start rc-local.service #启动

sudo systemctl status rc-local.service #查看
输出 >: start xx.py
sudo systemctl stop rc-local.service #关闭

Win10:

1. Create a new pythonstart.bat file with the following content format:

cd /d d:

cd workspace
python main.py

pause

2. Place the pythonstart.bat file into the startup folder:

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp

Double-click the file to see if it runs normally.

After restarting the computer, the system will automatically open a cmd window and run the contents of pythonstart.bat.

If you close the current window, the python service will also stop running.

Clean logs regularly

cp /dev/null /home/.../nohup.out

Enter the scheduled task

crontab -e

crontab is executed regularly every minute:

*/1 * * * * service mysqld restart //Execute every 1 minute
*/10 * * * * service mysqld restart //Execute every 10 minutes
1
2
crontab is executed regularly every hour:

0 */1 * * * service mysqld restart //Executed every 1 hour
0 */2 * * * service mysqld restart //Executed every 2 hours
1
2
crontab is executed regularly every day:

0 10 * * * service mysqld restart //Execute 30 at 10 o'clock every day 19 * * * service mysqld restart //Execute 1 2 crontab
at 19:30 every day Execute regularly every week:


0 10 * * 1 service mysqld restart //Execute every Monday at 10:00
30 17 * * 5 service mysqld restart //Execute every Friday at 17:30
1
2
crontab is executed regularly every year:

0 10 1 10 * service mysqld restart //Executed at 10:00 on October 1 every year
0 20 8 8 * service mysqld restart //Executed at 20:00 on August 8 every year
 

in conclusion:

Coupled with the code sent to QQ email, it is simply delicious.

Guess you like

Origin blog.csdn.net/qq_55542491/article/details/132172710
Recommended