- 论坛徽章:
- 1
|
本帖最后由 jimmy14k 于 2014-04-02 11:22 编辑
话题一,你当初为什么选择了学习shell?
在2013年以前,我都没接触过linux,以前公司都用windows,不过我用windows写过很多批处理,比如批量录音转换(wav2mp3,呼叫中心录的wav太占空间,所以要转换)、文件名的重定义等等。
2013年后,换了公司,才开始接触linux,公司服务器太多,而且很多项目故障要等客户反馈,才处理,效率太低,所以才开始学linux shell和python
话题二,在你的实际工作中,用shell实现了哪些功能?请给出详细的背景介绍、完整的源代码和注释,这将是我们评选的重要标准之一,如有隐私信息请做无害化处理。
到现在为止,linux shell和python我还是半瓢水,主要用shell来检测程序运行的状态,还有java程序日志的监控,如果是常见的错误,根据开发同事的需求,进行自动处理,如果是非常见的错误,邮件通知自己。
python主要是用来处理数据库的,根据经纬度,从谷歌的xml获取位置信息,然后更新到数据库。
因为接触linux时间不长,我很多shell发问贴,都是工作中需要解决的关键问题,但是自己没能掌握,比如取2小时内日志中存在ERROR字符串的行,困惑我N久,最后CU发贴才解决。在awk、sed这两部分,掌握的不够。
jimmy_xml_google.py- import urllib2
- import xml.dom.minidom
- def getxmlinfo(lon,lat):
- url="http://maps.google.com/maps/api/geocode/xml?latlng=%s,%s&language=zh-CN&sensor=true" % (lat,lon)
- resp=urllib2.urlopen(url)
- rtn=resp.read()
- resp.close()
- dom = xml.dom.minidom.parseString(rtn)
- r = dom.getElementsByTagName("formatted_address")
- r = r[0].childNodes[0].nodeValue
- return r
-
-
-
-
- if __name__ == '__main__':
- getxmlinfo(110.23990,32.20596)
复制代码- #coding=utf-8
- import MySQLdb
- import jimmy_xml_google
- from datetime import date
- import sys
- default_encoding = 'utf-8'
- if sys.getdefaultencoding() != default_encoding:
- reload(sys)
- sys.setdefaultencoding(default_encoding)
- def upd_info():
- dbs=['z_subscves0','z_subscves1','z_subscves2','z_subscves3','z_subscves4','z_subscves5']
- #ym = date.today().strftime("%Y%m")
- ym = 201303
- i=0
- while i<len(dbs):
- conn = MySQLdb.connect(host='127.0.0.1',user='root',passwd='xxx',db=dbs[i],charset='utf8')
- cur = conn.cursor()
- cur.execute('set names utf8')
- #cur.execute("select count(*) from tbl_location_%s where (LOC_INFO = '未计算' or LOC_INFO = '' or LOC_INFO is NULL) and TERMINAL_TIME >= curdate()" % (ym))
- cur.execute("select count(*) from tbl_location_%s where (LOC_INFO = '未计算' or LOC_INFO = '' or LOC_INFO is NULL)" % (ym))
- rs = cur.fetchall()
- if len(rs)>0:
- rtn = rs[0][0]
- print ('%s:%s' % (dbs[i],rtn))
- #query_wjs = "select LOCATION_PK,TERMINAL_SIM,LON,LAT from TBL_LOCATION_LAST WHERE (LOC_INFO = '未计算' or LOC_INFO = '' or LOC_INFO is NULL) and TERMINAL_TIME >= curdate()"
- cur.execute("select LOCATION_PK,TERMINAL_SIM,LON,LAT from TBL_LOCATION_%s WHERE (LOC_INFO = '未计算' or LOC_INFO = '' or LOC_INFO is NULL)" % (ym))
- rs_wjs = cur.fetchall()
- if len(rs_wjs)>0:
- for rtn_wjs in rs_wjs:
- rsp = jimmy_xml_google.getxmlinfo(rtn_wjs[2],rtn_wjs[3])
- print rtn_wjs[0],rtn_wjs[1],rtn_wjs[2],rtn_wjs[3],rsp
- cur.execute('set names utf8')
- cur.execute("update TBL_LOCATION_%s SET LOC_INFO = '%s' WHERE LOCATION_PK = '%s' and TERMINAL_SIM = '%s' and (LOC_INFO = '未计算' or LOC_INFO = '' or LOC_INFO is NULL)" % (ym,rsp.encode('utf-8'),rtn_wjs[0],rtn_wjs[1]))
-
- cur.close()
- conn.close()
- i=i+1
-
-
-
- if __name__ == '__main__':
- upd_info()
复制代码 |
|