
shell
彭世瑜
记录我的工作学习笔记
展开
-
shell/bash:nohup脚本控制程序启动停止重启
自定义配置需要修改:脚本名称 process_name启动命令函数 function start停止命令函数 function stop 正常不需要修改run_spider.sh#!/bin/bash# 配置要启动关闭的脚本名process_name="run_spider.py"# 添加启动命令function start(){ echo "start..."...原创 2019-11-06 12:15:51 · 3000 阅读 · 0 评论 -
shell变量设置默认值
1、使用if判断#!/bin/basha="" if [ ! $a ]; then a="default"fi echo $a# default2、使用默认值写法#!/bin/bashb="default"# 当变量a为null时echo ${a-$b}# default#当变量a为null或为空字符串时a=""echo ${a:-$b}...原创 2019-11-06 11:44:47 · 4081 阅读 · 0 评论 -
Shell脚本监控mongo并自动重启
本来可以用supervisor,不过占用内容有点多,服务器扛不住,所以自己写脚本监控监控代码/opt/monitor/monitor-mongo.sh# 检查mongo是否还在进程中count=`ps aux|grep mongo| grep -v grep |wc -l`echo $count now=$(date "+%Y-%m-%d %H:%M:%S")if [ $cou...原创 2019-10-29 16:17:23 · 1286 阅读 · 0 评论 -
shell script快速入门-基础语法
第一个脚本sh01.sh#!/bin/bashecho "hello"执行bash sh01.sh区别source: 父进程中执行bash:子进程中执行实例 1:姓+名->姓名#!/bin/bash# program: input firstname and lastname, output fullname# data: 2018-07-11...原创 2018-07-12 17:00:47 · 989 阅读 · 0 评论 -
sublime配置shell脚本解释器
新建编译文件shell.sublime-build, 编译系统选择自动即可{ "cmd": ["bash", "$file"], "selector": "source.shell"}hello.sh#!/bin/bashecho "hello world"原创 2018-07-13 14:33:05 · 10190 阅读 · 0 评论 -
把书读薄-Shell入门基础
运行1、作为可执行程序#!/bin/bash # 指定解释此脚本文件的程序$ chmod a+x test.sh # 使脚本具有执行权限$ ./text.sh # 执行脚本./test.sh # 在当前目录找test.sh # 去 PATH 里寻找2、作为解释器参数$ bash t...原创 2019-07-04 15:41:49 · 943 阅读 · 0 评论