失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > Ubuntu 18.04设置开机启动脚本

Ubuntu 18.04设置开机启动脚本

时间:2019-06-05 07:05:29

相关推荐

Ubuntu 18.04设置开机启动脚本

工作或生活当中,常常存在这样的需求:将常用的工具、服务做成开机启动项,省去开机后手动触发启动的麻烦。今天在这里记录下Ubuntu 18.04上如何设置开机启动。

一、首先编写一个可执行的启动脚本/root/.runCommandOnBoot.sh

#!/bin/bash#shadowsocks/usr/local/bin/sslocal -c /etc/shadowsocks.json -d start

二、设置开机执行该脚本

root@ThinkPad-T450s:~# crontab -eno crontab for root - using an empty oneSelect an editor. To change later, run 'select-editor'.1. /bin/nano <---- easiest2. /usr/bin/vim.basic3. /usr/bin/vim.tiny4. /usr/bin/code5. /bin/edChoose 1-5 [1]: 1 #这里选择1

接着出现下面的信息:

# Edit this file to introduce tasks to be run by cron.## Each task to run has to be defined through a single line# indicating with different fields when the task will be run# and what command to run for the task## To define the time you can provide concrete values for# minute (m), hour (h), day of month (dom), month (mon),# and day of week (dow) or use '*' in these fields (for 'any').## Notice that tasks will be started based on the cron's system# daemon's notion of time and timezones.## Output of the crontab jobs (including errors) is sent through# email to the user the crontab file belongs to (unless redirected).## For example, you can run a backup of all your user accounts# at 5 a.m every week with:# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/## For more information see the manual pages of crontab(5) and cron(8)## m h dom mon dow command

在该文件的末尾追加如下信息

@reboot /root/.runCommandOnBoot.sh

保存并退出。控制台出现如下信息,表示创建成功。

crontab: installing new crontab

如果觉得《Ubuntu 18.04设置开机启动脚本》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。