
Bash
代元培
听风看雨 见贤思齐 抚霜踏雪 青云直上
展开
-
计算Shell脚本执行时间
统计Shell脚本执行时间原创 2022-11-14 12:02:01 · 1847 阅读 · 1 评论 -
Shell执行SQL发邮件
Shell脚本执行SQL语句,获得结果发邮件原创 2022-07-28 14:33:00 · 216 阅读 · 0 评论 -
shell汇总线上日志
脚本获取线上所有机器日志集中到本地单个文件原创 2022-06-20 16:16:13 · 150 阅读 · 0 评论 -
download_data.sh
用于从sftp集群中下载数据文件到本地原创 2021-11-23 11:37:03 · 1839 阅读 · 0 评论 -
DataX脚本任务开发实例
DataX脚本任务开发实例记录原创 2021-07-20 19:17:59 · 598 阅读 · 0 评论 -
邮件监控云上脚本执行进度
#!/bin/sh#监控云上pay-data-load脚本执行进度current_path=$(cd "$(dirname $0)"; pwd)data_path="$current_path/time/"file_input=$current_path/file_inputhtml_file=$current_path/pay_data_load.htmlif [ -f "$html_file" ];then rm $html_filefi#if [ -f "$file_...原创 2021-07-09 11:35:37 · 192 阅读 · 0 评论 -
awk统计行数&去重展示
# 统计第4列为0112并且第5列为00或者03的行数awk -F '|' '{if(($4=="0112")&&($5=="00"||$5=="03")) print $1}' epcc0303_20210423.txt|wc -l# 去重展示第一列的时间awk -F '|' '{print $1}' epcc0303_20210422.txt|sort|uniq原创 2021-05-08 19:15:20 · 1827 阅读 · 0 评论 -
Shell字符串拼接及替换脚本示例
#!/bin/bash. ~/.bashrcdateEnd=`date +"%Y%m%d"`dateBegin=`date +%Y%m%d -d"-30 day $dateEnd"`if [ $# == 1 ]; then if [ ! -n "$(echo $1| sed -n "/^[0-9]\+$/p")" ]; then echo "FATAL: The parameter is not a number." exit -1 fi i.原创 2021-04-16 17:26:56 · 632 阅读 · 0 评论 -
awk指定列求和简单示例
20000000000069|950615951|2019-04|3.7020000000000069|950615951|2019-05|1.3020000000000069|950615951|2019-06|1.3020000000000069|950615951|2019-08|1.5020000000000069|950615951|2019-09|1.4020000000000069|950615951|2019-10|1.6020000000000069|950615951|20.原创 2021-04-09 17:51:41 · 453 阅读 · 0 评论 -
Shell循环日期执行脚本
#!/bin/bash. ~/.bashrcif [ $# == 1 ]; then dateBegin=$1 dateEnd=$dateBeginelif [ $# == 2 ]; then dateBegin=$1 dateEnd=$2else echo "dateBegin or dateEnd is empty." exit -1fischema="fn"tbname="t_bank_return"dateBegin=`date +.原创 2021-03-25 17:41:24 · 1132 阅读 · 2 评论 -
update_time.sh
# 当前脚本路径currentPath=$(cd "$(dirname $0)";pwd)cd $currentPathcd ..# 数据类型dataType=$1# 获取当前时间记录文件getDate=`head time/${dataType}.time`# 当前时间+1天getDate=`date -d"+1 day $getDate" +%Y%m%d`# 更新时间写入文件echo $getDate > time/${dataType}.time# 删除3个.原创 2021-02-04 10:29:41 · 132 阅读 · 0 评论 -
shell中for循环拼接字符串
# test.sh# 在当前目录下创建文本文件temp,如果文件存在则清空文件$(> temp)# for 循环将参数追加到当前目录的temp文件,逗号分隔,echo -n 不换行for i in $*;do ((n++)) # 从第四个开始拼接 if [[ n -gt 3 ]];then echo -n ${i}, >> temp fidone# str取temp文本里的字符串str=$(cat temp)# 将字符串最后的一个逗号去掉str=${str%.原创 2021-01-21 17:00:56 · 6421 阅读 · 0 评论 -
walletInfo.sh
#!/bin/bashCUR_DIR=$(cd "$(dirname "${BASH_SOURCE-$0}")";pwd)exec 1>>$CUR_DIR"/log/sh.log"exec 2>>$CUR_DIR"/log/sh.log.wf" . ~/.bashrcfilename=$1readfile=$CUR_DIR/var/${filename}echo $datafilecurrentdate=`date +'%Y%m%d'`current=`date .原创 2021-01-21 15:53:32 · 164 阅读 · 0 评论 -
spIdToSpUid.sh
#!/bin/bashCUR_DIR=$(cd "$(dirname "${BASH_SOURCE-$0}")";pwd)exec 1>>$CUR_DIR"/log/spIdToSpUid.log"exec 2>>$CUR_DIR"/log/spIdToSpUid.log.wf" . ~/.bashrcfileName=$1dateStr=`date +'%Y%m%d'`current=`date "+%Y-%m-%d %H:%M:%S"`timeStamp=`d.原创 2021-01-21 14:15:07 · 138 阅读 · 3 评论 -
loadnginx.sh
#! /bin/bash# 基于 odp3.0的nginx,适用于odp3.0以下和odp3.0版本的nginx ,增加强制kill container里面的nginx的逻辑# 20160129 升级chkconfig 增加创建log/webserver 目录部分#set -eset -Etrap 'echo "Fail unexpectedly on ${BASH_SOURCE[0]}:$LINENO!" >&2' ERRODP_ROOT=$(readlink -f `.原创 2021-01-21 11:52:10 · 200 阅读 · 0 评论 -
server.sh
app_name='pay-data-platform'app_path=$(cd $(dirname $0); pwd)command=$1cmd_nginx="${app_path}/webserver/loadnginx.sh"cmd_fpm="${app_path}/php/sbin/php-fpm"if [ "$command" == 'start' ]; then $cmd_fpm start $cmd_nginx startelif [ "$command" == 'res.原创 2021-01-21 11:44:31 · 311 阅读 · 0 评论 -
shell判断404
wget -O output2.tar.gz http://irep.build.daiyp.com/product/v3/download/release/dxm/pay-core/payserver-conf/latest/output.tgzif [ ! -s output2.tar.gz ];then echo '404';fi原创 2021-01-12 20:36:57 · 434 阅读 · 0 评论 -
启动脚本和守护进程
#!/bin/bash# load_dypserver.shname='dypserver'SV="./supervise.$name"unalias pidof &>/dev/nullexec 0</dev/null#ulimit -c unlimitedcd `dirname $0`#LIBRDKAFKA_DIR=`pwd`/lib#export LD_LIBRARY_PATH=$LIBRDKAFKA_DIR:$LD_LIBRARY_PATHif [ ! -.原创 2020-12-25 10:45:03 · 364 阅读 · 0 评论 -
shell脚本写入多行内容
if [ `grep -c "*.*.*.*" $CURRENT_DIR/conf/ubclient.conf` -eq '0' ];thenecho -e "\n" >> $CURRENT_DIR/conf/ubclient.confcat>>$CURRENT_DIR/conf/ubclient.conf<<EOF[.UbClient][..@Service]Name : testConnectAll : 0DefaultConnectTimeOut.原创 2020-12-18 15:00:13 · 2365 阅读 · 3 评论 -
生成分库分表建表语句SQL
#!/bin/bash. ~/.bashrctime=$(date "+%Y-%m-%d %H:%M:%S")echo "${time}"for ((i=0;i<100;i++));do printf "%02d " $i; db_no=`printf "%02d\n" $i` sed 's/_62/_'"$db_no"'/g' translog.txt > translog_${db_no}.txt exit nohup mysql -h1.1.1.原创 2020-12-16 19:02:19 · 725 阅读 · 0 评论 -
offline_transfer.sh
#!/bin/sh# 监控报表PHP_EXE=${PHP_EXE:=/home/work/scripts/php/bin/php}PHP_INI=${PHP_INI:=/home/work/scripts/php/etc/php.ini}ROOT=$(cd "$(dirname $0)"; pwd)OUT="$ROOT/offline_transfer.out"MAIN="$ROOT/imp/OfflineTransfer.php"current_date=`date +%Y%m%d`.原创 2020-12-09 14:04:31 · 133 阅读 · 0 评论 -
shell for循环固定步长
#!/bin/bash. ~/.bashrcfor((i=0;i<1000;i+=4));doecho \{\"jdbcUrl\":[\"jdbc:mysql://1.1.1.1:5500/dyp_db\"],\"table\":[\"t_did_2_uid__tablet_${i}\"]\}, >> make-conf.txtdoneecho "make-conf.sh done"原创 2020-12-02 17:10:17 · 2332 阅读 · 0 评论 -
shell中if [[ -e -d -f ]]; 详解
文件表达式-e filename 如果 filename存在,则为真-d filename 如果 filename为目录,则为真-f filename 如果 filename为常规文件,则为真-L filename 如果 filename为符号链接,则为真-r filename 如果 filename可读,则为真-w filename 如果 filename可写,则为真-x filename 如果 filename可执行,则为真-s filename 如果文件长度不为0,则为真-h ...原创 2020-11-26 16:18:32 · 958 阅读 · 0 评论 -
while [ -n “$1“ ]; do
path=$(pwd)"/odp_auto"code=0need_code=0need_conf=0odp=0start=0stop=0proxy=0 while [ -n "$1" ]; do # -n str,字符串不为null,长度大于零 case "$1" in -path) path=$2 ;; -code) code=$2 need_code=1 ;; -conf).原创 2020-10-27 11:41:04 · 1290 阅读 · 0 评论 -
shell脚本实现文件上传ftp
#!/bin/bash. ~/.bashrctime=$(date "+%Y-%m-%d %H:%M:%S")echo "${time}"f_day=`date +%Y%m01`echo ${f_day}sed "s/F_DAY/${f_day}/g" t_bi_cost_sql > t_bi_cost.sqlcat t_bi_cost.sql | gp_rd_h > PAY_TO_HY_DEPT_FEE.CSVsed -i '$d' PAY_TO_HY_DEPT_FEE.CS.原创 2020-09-02 15:34:24 · 1907 阅读 · 0 评论 -
shell获取时间日期
# 当前日期current_date=`date +%Y%m%d`time=$(date "+%Y-%m-%d %H:%M:%S")echo "${time}"# 当月第一天f_day=`date +%Y%m01`echo ${f_day}# 昨天日期targetDay=`date -d "-1 days" +"%Y%m%d"`yesterday_date=`date -d 'yesterday' +%Y-%m-%d`# 前天日期qtday=`date -d '2 day ago' .原创 2020-09-02 15:24:44 · 1058 阅读 · 0 评论 -
shell删除文件最后一行
# 删除文档的第一行sed -i '1d' <file># 删除文档的最后一行sed -i '$d' <file>原创 2020-09-02 10:15:36 · 4683 阅读 · 0 评论 -
gpfdist-start.sh
#!/bin/bash# run in v2basepath=$(cd `dirname $0`; pwd)DATAPATH="/home/work/datax/ext"SERVICEPORT=9902LOGFILE="/home/work/gpfdist/gp-client/log/gpfdist.log"TIMEOUT=300if [ -f ${LOGFILE} ]then datenow=` date +'%Y%m%d'` mv ${LOGFILE} ${LO.原创 2020-08-06 11:14:26 · 178 阅读 · 0 评论 -
shell脚本备份gp表数据
#!/bin/bash. ~/.bashrcexport LANG="zh_CN.UTF-8"export LC_ALL="zh_CN.UTF-8"current_date=`date +%Y%m%d`echo ${current_date}basepath=$(cd `dirname $0`; pwd)cd ${basepath}tempfile="${basepath}/temp.log"export PGPASSWORD=******ONE_SQL="\\copy (select.原创 2020-08-03 19:18:27 · 390 阅读 · 0 评论 -
psql免密登陆
# 将密码写在客户端服务器的用户家目录下,创建一个.pgpass文件,并将权限设置为0600,就可以实现了# .pgpass文件格式如下,每行一个hostname:port:database:username:password# shell执行命令psql -h 地址 -p 端口 -U 用户 -c "CREATE DATABASE test"alias gp_rd='psql -h x.x.x.x -p 5432 -d gp_pay -U gp_rd...原创 2020-07-31 11:20:49 · 1141 阅读 · 0 评论 -
shell输出01到99
seq 99seq -f %02.0f 99seq -f %02.0f 100 120原创 2020-07-30 15:36:15 · 1182 阅读 · 0 评论 -
DataX分库分表脚本实现
#!/bin/bash. ~/.bashrcif [ $# -lt 1 ]then echo "./loaddata db_no" exitfidb_no=$1time=$(date "+%Y-%m-%d %H:%M:%S")echo "${time}"example="/home/work/datax/job/core/example"tempdir="/home/work/datax/job/core"basepath=$(cd `dirname $0`; pwd.原创 2020-07-28 17:27:10 · 1098 阅读 · 2 评论 -
shell去除字符串前所有的0
str='0099'new_str=$(echo -e $str | sed -r 's/0*([0-9])/\1/') # 99原创 2020-07-28 15:49:24 · 2125 阅读 · 0 评论 -
alias sp
#!/bin/sh. ~/.bashrcre="[[:digit:]]+"fields="F_sp_id, F_sp_user_id, F_sp_company, F_sp_display_name, F_create_time"if [[ $1 =~ $re ]]; then fndb -e "SELECT $fields FROM db_name.t_scenario_sp_map WHERE F_sp_id = '$1'\G" exit 0elif [ "$1" =.原创 2020-05-09 15:51:01 · 122 阅读 · 0 评论 -
awk把列式转为逗号隔开的行
awk -F' ' '{print $1}' uids | xargs | tr ' ' ',' >> uids_row原创 2020-05-09 14:52:34 · 980 阅读 · 0 评论 -
awk第一列求和
cat a.txt | awk '{sum+=$1} END {print "Sum = ", sum}'原创 2020-05-09 14:51:09 · 987 阅读 · 0 评论 -
shell while do
#!/bin/shROOT=$(cd "`dirname $0`/.."; pwd)PHP_EXE=${PHP_EXE:=/home/work/pay-data-scripts/php/bin/php}PHP_INI=${PHP_INI:=/home/work/pay-data-scripts/php/etc/php.ini}channelCode=if [ $# == 1 ];...原创 2020-05-08 17:45:34 · 729 阅读 · 0 评论 -
monitor.sh
#!/bin/bash. ~/.bashrccurrent_date=`date +%Y-%m-%d`echo ${current_date}basepath=$(cd `dirname $0`; pwd)cd $basepathMONITOR_BEGIN=/home/work/daiyuanpei/monitor-beginif [ "`ls -A ${MONITOR_BEGIN...原创 2020-05-07 16:18:57 · 245 阅读 · 0 评论 -
monitor-fail.sh
#!/bin/bash. ~/.bashrccurrent_date=`date +%Y-%m-%d`echo ${current_date}basepath=$(cd `dirname $0`; pwd)cd $basepathFAIL_PATH=/home/work/daiyuanpei/monitor-failif [ "`ls -A ${FAIL_PATH}`" = ""...原创 2020-05-07 16:08:56 · 193 阅读 · 0 评论 -
start_datax.sh
#!/bin/bash. ~/.bashrcecho $#if [ $# -lt 1 ]then echo "need job config file" exitfijobname="$1"taskname=`echo $(basename $jobname .xml)`echo "$jobname,taskname=$taskname"DATAX_HOME=...原创 2020-05-07 14:16:20 · 130 阅读 · 0 评论