爬虫服务器后台执行命令

命令一: crontab

定期执行爬虫,注意: 设置的周期内爬虫应执行完,否则会产生一堆的后台任务进程
在线crontab表达式验证工具

service crond status            查看crontab状态
crond start                     开启crond

crontab -e                      编辑
sudo select-editor              选择编辑器
crontab -l                      显示
/etc/init.d/cron                配置文件
sudo /etc/init.d/cron start     启动
sudo /etc/init.d/cron stop      关闭
sudo /etc/init.d/cron restart   重启
sudo /etc/init.d/cron reload    重新载入配置
ps aux | grep cron              查看cron是否已启动

分	时	日	月	周	命令
*	*	*	*	*	command
crontab -e  编辑
crontab -l  显示
crontab -r  删除
crontab -i  删除时给提示
命令二: screen

开启会话运行爬虫,退出会话后,断开服务器连接不会中断爬虫执行

screen -S mac       创建mac会话
screen -ls          查看mac会话  
screen -r  mac      恢复mac会话
screen -d mac       下线mac会话
screen -wipe mac    清除mac会话

解决screen状态为Attached连上不的问题
screen -D -d session_id   下线已打开的会话

ctrl + a + d        退出会话
ctrl + d            关闭会话
命令三: nohup

运行爬虫程序,退出帐户时该进程不会结束

bash test.sh                          正常输出
nohup bash test.sh &                  后台输出
nohup bash test.sh > out.log 2>&1 &   指定输出
jobs -l                               查看任务

ps aux | grep test.sh                 查看PID
kill PID                              杀死程序
#!/bin/bash

int=1
while(( $int<=100 ))
do
    echo $int
    let "int++"
    sleep 1
done
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值