惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
Kaspersky official blog
T
Threat Research - Cisco Blogs
N
News and Events Feed by Topic
Hacker News: Ask HN
Hacker News: Ask HN
Project Zero
Project Zero
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
Security Latest
Security Latest
Spread Privacy
Spread Privacy
aimingoo的专栏
aimingoo的专栏
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
U
Unit 42
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Scott Helme
Scott Helme
Engineering at Meta
Engineering at Meta
Microsoft Security Blog
Microsoft Security Blog
T
The Blog of Author Tim Ferriss
A
About on SuperTechFans
爱范儿
爱范儿
S
Schneier on Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Schneier on Security
Schneier on Security
Latest news
Latest news
GbyAI
GbyAI
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
PCI Perspectives
PCI Perspectives
Jina AI
Jina AI
AI
AI
NISL@THU
NISL@THU
I
Intezer
G
GRAHAM CLULEY
B
Blog
S
Secure Thoughts
IT之家
IT之家
宝玉的分享
宝玉的分享
Recent Announcements
Recent Announcements
Y
Y Combinator Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
有赞技术团队
有赞技术团队
V2EX - 技术
V2EX - 技术
Recorded Future
Recorded Future
Hacker News - Newest:
Hacker News - Newest: "LLM"

博客园 - 走到天亮

设计模式之“适配器模式” 设计模式之“门面模式” 设计模式之“抽象工厂模式” 设计模式之“单例模式” 设计模式之“代理模式” 设计模式之“策略模式” 《C# to IL》第三章 选择和循环 《C# to IL》第二章 IL基础 《C# to IL》第一章 IL入门 淘宝下单高并发解决方案(转载) java linux 配置环境 Spring Aop之(二)--Aop 切面声明和通知 Spring aop Spring RegexpMethodPointcutAdvisor和NameMatchMethodPointcutAdvisor Spring BeanNameAutoProxyCreator 与 ProxyFactoryBean CentOS的IP配置专题 Spring Bean属性绑定Bean返回值 【阿里的感悟】质量该如何做? .(转载) Ubuntu开机自动启动script(2)
Ubuntu开机自动启动Script
走到天亮 · 2011-04-28 · via 博客园 - 走到天亮

实现目标:

(1).在Ubuntu启动时,自动运行位于普通用户test1根目录下的脚本程序start.py,该程序会在每次执行时自动向本地日志文件追加一条记录,源码如下:

from datetime import datetime
now
=datetime.now()
f
=open('test1.log','a')
f.write(
'%s '%now)
f.close()

Ubuntu在启动时,会自动执行/etc/rc.d目录下的初始化程序,因此我们可以把启动任务放到该目录下:

  1、init.d目录下都为可执行程序,他们其实是服务脚本,按照一定格式编写,Ubuntu在启动时会自动执行,类似Windows下的服务

  2、用root帐号登录,vi /etc/rc.d/init.d/mystart,追加如下内容:

#!/bin/bash
#
chkconfig:2345 80 05 --指定在哪几个级别执行,0一般指关机,
6指的是重启,其他为正常启动。80为启动的优先级,05为关闭的优先机
#description:mystart service
RETVAL=0
start(){ 
--启动服务的入口函数
echo 
-"mystart serive ..."
cd 
/home/test1
su test1 
-"python /home/test1/test.py"
}
stop(){ 
--关闭服务的入口函数
echo 
"mystart service is stoped..."
}
case $
1 in --使用case,可以进行交互式操作
start)
start
;;
stop)
stop
;;
esac
exit $RETVAL

     3、运行chmod +r /etc/rc.d/init.d/mystart,使之可直接执行

  4、运行chkconfig --add mystart,把该服务添加到配置当中

  5、运行chkconfig --list mystart,可以查看该服务进程的状态