该Shell脚本可以实现批量将sql文件导入多个数据库,数据库可以灵活设置
#!/bin/bash
path=/home/xxx/db.txt
user=test
password=test
port=xxx
host=x.x.x.x
ll /home/xxx/exports > db.txt #获取导入的数据库文件名称
cat $path |while read line
do
dbname=`echo $line|awk '{print $NF}' |awk -F. '{print $1}'`
echo $dbname #获取数据库
echo $line
/usr/local/mysql/bin/mysql -h$host -u$user -p$password -P$port -D$dbname < /home/xxx/exports/$line #此方式比Source要高一些
done
#Json中提取字段,并写入EXCEL,写入的时候起始行可能有误...,另path中文件名称最好不要以X开头,会有报错,不知道原因为何。
import json
import xlwt
class get_interests(object):
def __init__(self,path):
self.path=path
def open_interests_txt(self):
excel= xlwt.Workbook()
sheet=excel.add_sheet('interests')
with open(self.path,'r+') as interests:
xq_txt=json.loads(interests.read())
print type(xq_txt)
print xq_txt['data']
print len(xq_txt['data'])
i=0
for item in xq_txt['data']:
print item['path']
if i<len(xq_txt['data']):
i=i+1
for j in range(0,len(item['path'])):
#print item['path'][j]
print i,j,item['path'][j]
sheet.write(i,j,item['path'][j])
excel.save('a4.xls')
def get_name(self):
with open(self.path,'r+') as interests:
xq_txt=json.loads(interests.read())
for item in xq_txt['data']:
print item['name']
path='F:\\PROJECT\\python\\code\\Study_1\\src\\20170509\\ww.json'
test=get_interests(path)
#test.open_interests_txt()
test.get_name()
好久不写了,以上两段是最近用到的,算是一点点的积累。比较菜,高手请勿鄙视。