linux/mac 实用脚本

linux/mac 实用脚本

知识

set -ex: -e:命令失败后立即结束 -x:打印每条执行的命令

mysqldump

MySQL mysqldump数据导出详解 复制表,调用方式:sh copy.sh "-h127.0.0.0 -uroot -P8306 -p123456 boss_develop"

#!/bin/bash
#set -x
REMOTE_HOST=$1
echo REMOTE_HOST:$REMOTE_HOST
oldifs=$IFS
dump(){
# -C启用压缩 --skip-triggers 不导出触发器
mysqldump -h10.69.34.205 -uadmin -P9800 -pDc@20120225 --opt -C boss $1 | mysql $REMOTE_HOST
}
dtd(){
IFS=$oldifs
arr=($1)
for table in ${arr[@]}
do
echo start dump $table
dump $table
done
IFS=$'\n'
}
IFS=$'\n'
#crm_measurement_units crm_department crm_role_extend crm_price_item_ref_measure_time crm_time_units
#crm_special_rules_item crm_special_rules_product_item_rel crm_special_rules_product_type_rel
#dw_manual_rule dw_slice_rule
#crm_account_director crm_employee crm_region_base
tables="
crm_product_type crm_product_line_group
crm_account crm_contract contract_account_release crm_product_type_relation contract_product_price
crm_price_definition crm_price_detail
crm_special_rules_discount crm_contract_sprules crm_contract_sprules_regions
crm_rule_use_log crm_rule_use_lock crm_manual_rule crm_manual_rule_lock
month_bill_locked month_bill_summary_new
"
for table in ${tables[@]}
do
read -r -p $table" ? [Y/n] " input
case $input in
[yY][eE][sS]|[yY]) dtd "${table}" ;;
*) echo "No";;
esac
done
IFS=$oldifs
echo finish copy
read

部署ss服务器教程

阿里云搭建SS代理超详细教程!!! - 天涯小嘿嘿 - 博客园 脚本来源:teddysun/shadowsocks_install

#安装
wget --no-check-certificate -O shadowsocks-all.sh https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-all.sh
chmod +x shadowsocks-all.sh
./shadowsocks-all.sh 2>&1 | tee shadowsocks-all.log
#卸载
./shadowsocks-all.sh uninstall

服务状态检测

#!/bin/sh
service="boss-api-8086 boss-server-8080 boss-activiti-8095 boss-ruleconvert-8090 boss-bill-8071 boss-sync-8100"
for service in ${service[@]}
do
if test $(pgrep -f $service | wc -l) -eq 0
then
echo "ERROR "$service" NOT RUNNING"
else
echo $service" is runing....."
fi
done
echo "check process finish,any key to exit"
read

实用命令

获取父线程名称 get the name of the caller script in bash script

echo $(ps $PPID | tail -n 1 | awk "{print \$5}")

简单for循环curl测试下载速度/for循环写成一行 参考:linux脚本

```bash {cmd=true}

测速

for i in {1..10}; do echo $i">>>>"; curl -o /dev/null -s -w '%{time_connect}:%{time_starttransfer}:%{time_total}\n' 'https://lib.baomitu.com/jquery/3.3.1/jquery.min.js'; done

其他示例

for i in {1..10}; do echo 'test'; done for ((i=1;i<10;i++)); do echo 'test'; done for i in $(seq 1 10); do ehco 'test'; done

```