
shell
Clannad_汐
寒江孤影、相逢何必曾相识
展开
-
常用shell(3):shell监控nginx所有进程cpu,内存占用
1. 脚本 注: 仅centos测试通过,ubuntu测试失败# !/bin/bash# author:liaotuoif [ -e cpu_mr.log ]then rm -f cpu_mr.logfipid_array=(122)#get all pid by proNamefunGetPids(){ ps -C nginx -o pid > pids.txt原创 2017-08-17 00:47:09 · 2573 阅读 · 0 评论 -
常用shell(1):shell获取系统当前时间戳
1. shell脚本如下current=`date "+%Y-%m-%d %H:%M:%S"` timeStamp=`date -d "$current" +%s` #将current转换为时间戳,精确到毫秒 currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000)) echo $currentTimeStamp2. 运行效果原创 2017-08-13 00:36:27 · 96509 阅读 · 5 评论 -
常用shell(2):shell监控进程的cpu,内存占用(定时采集)
1. shell脚本#!/bin/bashpid=$1 #获取进程pidecho $pidinterval=1 #设置采集间隔while truedo echo $(date +"%y-%m-%d %H:%M:%S") >> proc_memlog.txt cat /proc/$pid/status|grep -e VmRSS >> proc_memlog.txt原创 2017-08-15 23:12:15 · 13490 阅读 · 2 评论 -
Shell 字符串拆分成数组
1. 字符串stringA="one,two,three,four"2. 拆分OLD_IFS="$IFS" IFS="," arr=($stringA) IFS="$OLD_IFS" for s in ${arr[@]} do echo "$s" done3. 输出one two three four原创 2017-08-28 13:43:28 · 1965 阅读 · 2 评论 -
shell常用条件表达式
文件表达式if [ -f file ] 如果文件存在if [ -d ... ] 如果目录存在if [ -s file ] 如果文件存在且非空 if [ -r file ] 如果文件存在且可读if [ -w file ] 如果文件存在且可写if [ -x file ] 如果文件存在且可执行 整数变量表达式if [ int1 -eq in原创 2017-10-30 12:09:52 · 1687 阅读 · 0 评论 -
shell常用代码块
1. 截取字符串中的数字echo "2014年7月21日" | tr -cd "[0-9]"2. 如果文件存在则删除if [ -e $FILE ] then rm -f $FILE fi3. 待续…原创 2017-08-17 23:51:29 · 2582 阅读 · 0 评论 -
shell获取天气预报
天气urlurl= “http://www.weather.com.cn/data/cityinfo/“+citycode+”.html” 衡阳 http://www.weather.com.cn/data/cityinfo/101250401.htmlshell$ curl http://www.weather.com.cn/data/cityinfo/101250401.html定时自动获原创 2017-11-30 11:25:27 · 2427 阅读 · 2 评论