linux开机自启脚本

方法一:rc.local

  将shell脚本绝对路径加入rc.local,并赋予执行权限

 

查看rc.local运行状态

  systemctl enable rc-local

  systemctl restart /etc/rc-local.service

  systemctl status /etc/rc-local.service

 

 

 

 

方法二:crontab

  在计划任务中加入:@reboot /usr/bin/redshift

 

方法三:/etc/rc.d/init.d/mystart

start(){ --启动服务的入口函数
#chkconfig:2345 80 05 --指定在哪几个级别执行,0一般指关机,
#!/bin/bash
#chkconfig:2345 80 05 --指定在哪几个级别执行,0一般指关机,6指的是重启,其他为正常启动。80为启动的优先级,05为关闭的优先机
#description:mystart service
RETVAL=0
start(){ 
echo -n "mystart serive ..."
cd /root
su root -c "bash /root/ziqi.sh"
}

stop(){ 
echo "mystart service is stoped..."
}

case $1 in 
start)
start
;;
stop)
stop
;;
esac

授权 chmod +x /etc/rc.d/init.d/mystart

添加到配置:chkconfig --add mystart

查看该服务状态:chkconfig --list mystart

posted @ 2020-06-05 17:39  zk01  阅读(252)  评论(0编辑  收藏  举报