目录
Shell生产最常用的命令和脚本
#!/bin/bash #地址 HOSTNAME="123456" PORT="123456" USERNAME="123456" PASSWORD="123456"
datanode=(1 2 3) DBNAME=(dspcbdb dsanddb dsiosdb dsiobdb dsanbdb) a=0
for node in ${datanode[@]} do for DB in ${DBNAME[@]} do for i in {0..30} do my=`printf %02d $i`
alter_sql="alter table tbl_dsbiz_detail_inf$my add check_value varchar(128) not null default ' ',add sim_mb varchar(128) not null default ' ';"
mysql -h${HOSTNAME} -P${PORT} -u${USERNAME}@${node} -p${PASSWORD} ${DB} -A -e "${alter_sql}"
((a++));
done done done echo "需要处理1500张表,共处理了$a张表"
<<COMMENT 把语句写在这个里面可以注释 COMMENT time=`date "+%Y%m%d"`
seconds=(3 2 1) a=0 #删库脚本增加提示选项避免误操作 read -p "Warning: your DBNAME is [ "$DBNAME" ] Honey,do you really want to execute this script? Enter yes if you are sure: " honey if [ "$honey" == "yes" ]; then
time=`date "+%Y%m%d"` read -p "Please input your lucky number:" date2 if [ $date2 == $time ]; then for sec in ${seconds[@]} do echo "输入正确 脚本"$sec"秒后开始执行" sleep 1 done delete_sql="truncate table tbl_dsbiz_index_inf$my;" result1=`mysql -h${HOSTNAME} -P${PORT} -u${USERNAME}@${node2} -p${PASSWORD} ${DBNAME} -A -e "${select_sql}" | sed -n '2p'`
if [ $result1 -eq 0 ]; then
echo "执行查询命令成功!" ((c++)); else echo "执行查询命令失败!" echo $result1 exit 0 fi
cre_sql=`CREATE TABLE 'tbl_dsbiz_index_inf00' ( 'id' bigint(11) NOT NULL AUTO_INCREMENT, 'idx_key' varchar(128) NOT NULL DEFAULT '', 'value' varchar(128) NOT NULL DEFAULT '', 'score' double(20,0) NOT NULL DEFAULT '0', 'rec_crt_ts' timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP, 'exp_ts' timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP , PRIMARY KEY ('id'), UNIQUE KEY 'unique_key_value' ('idx_key','value'), KEY 'key_idx_key' ('idx_key') USING BTREE, KEY 'key_score' ('idx_key','score') USING BTREE, KEY 'key_rec_crt_ts' ('rec_crt_ts') USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;`
count2=$((3*c))
create_sql="create table tbl_dsbiz_index_inf$my like tbl_dsbiz_index_inf00;"
delete_sql="drop table tbl_dsbiz_index_inf$my;" alter_sql="desc tbl_dsbiz_detail_inf$my;" result=`mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} ${db1} -A -e "${alter_sql}" | sed -n '6p' | awk '{print $1}'`
if [ "$result" = "check_value" ];then fi
insert_sql="insert into tbl_dsbiz_index_inf$my(id,idx_key,value,score,rec_crt_ts,exp_ts) values('$j','"$j"key','"$j"yyliu','"$j"100',now(),now());"
select_sql="select table_schema,table_name,data_free/1024/1024,engine from information_schema.tables where table_schema not in ('information_schema','mysql') and data_free>0;"
total=$((a+b+c))
day=`date -d "-1 day" "+%Y%m%d"` time_1=`printf %02d $i` time_1tps=`date -d "-1 day" "+%Y%m%d-$time_1:00:00"`
bdxx_inf=`redis-cli -h ${HOSTNAME_PARA} -p ${PORT_PARA} -a ${ACCESS} get dcs_mgps:110004:info_query:"$time_2tps":tps`
stormUIIp=172.21.12.9:1808 url_nimbus=http://"$stormUIIp"/api/v1/nimbus/summary var_numbus=`curl $url_nimbus` echo $var_numbus | python -m json.tool
insert into tbl_aubiz_dev_mchnt_inf(dev_id,mchnt_cd,rec_crt_ts,rec_upd_ts) values ("a7d74339ad981647","822331051371370",now(),now());
select mchnt_cd,count(*) from tbl_aubiz_user_mchnt_inf where mchnt_cd="822361053119998";
update tbl_aubiz_sys_para_inf set value=101 where seq_id="36"&¶_id="hackScore";
delete from tbl_aubiz_bankcard_inf where user_id="1310d8f372c14be5a14d107917823d10";