技巧1: 定时任务 Crontab
-
打开:
sudo crontab -e -
使用规则
m h dom mon dow command 分钟 小时 日 月 星期(0~6,0表示周日) 命令 0 6,11,17,22 */5 * * sh autosend.sh 符号 意义 * 代表所有的取值范围内的数字; / 代表”每”(“*/5”,表示每5个单位) - 代表从某个数字到某个数字(“1-4”,表示1-4个单位) , 分开几个离散的数字;
技巧2: Ubuntu 18.04 启动服务/开机自启
-
systemctl 命令:
描述 命令 启动/关闭/重启 服务 systemctl start/stop/restart service-name查看状态 systemctl status service-name开机启动 systemctl enable service-name取消开机启动 systemctl disable service-name开机启动状态 systemctl is-enabled service-name -
参考自:How to Enable or Disable Services in Ubuntu Systemd/Upstart
技巧3: Ubuntu 18.04 启动执行 shell 脚本
-
新建 shell 脚本,并赋予执行权限 `chmod u+x /path/to/shell/start.sh
-
在
/etc/systemd/system文件夹下新建.service文件start.service,格式如下:1 2 3 4 5 6 7 8
[Unit] Description=Auto Start service [Service] ExecStart=/path/to/shell/start.sh [Install] WantedBy=multi-user.target
-
开机启动:
sudo systemctl enable first
技巧4: SSH 超时
1
2
3
4
5
# 客户端设置定时心跳,比如每60秒发一次心跳,失败3次就不再发送
# /etc/ssh/ssh_config
ServerAliveInterval 60
ServerAliveCountMax 3
技巧5: 给 apt 设置代理
1
2
3
4
5
6
sudo vi /etc/apt/apt.conf.d/proxy.conf
# paste
Acquire {
HTTP::proxy "http://127.0.0.1:8080";
HTTPS::proxy "http://127.0.0.1:8080";
}