This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
path 本地文件夹路径,scp使用了-r | |
user 服务器的用户名 | |
passwd 服务器的密码 | |
tpath 上传到服务器的路径 | |
''' | |
def scp(path, user,ip, passwd, tpath): | |
passwd_key = '.*assword.*' | |
shell = 'scp -r {path} {user}@{ip}:{tpath}'.format( | |
path=path, user=user, ip=ip, tpath=tpath |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# iptables操作,两种操作 | |
# 立即生效 | |
开启: service iptables start | |
关闭: service iptables stop | |
# 重启生效 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
加入上层目录和绝对路径 | |
''' | |
import sys | |
sys.path.append('..') #表示导入当前文件的上层目录到搜索路径中 | |
sys.path.append('/home/model') # 绝对路径 | |
from folderA.folderB.fileA import functionA | |
''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql root@localhost:(none)> show variables like '%max_connections%'; #查看mysql最大链接数 | |
+-----------------+-------+ | |
| Variable_name | Value | | |
+-----------------+-------+ | |
| max_connections | 151 | | |
+-----------------+-------+ | |
1 row in set | |
Time: 0.017s | |
mysql root@localhost:(none)> set global max_connections=1000; #将最大链接修改成1000 | |
Query OK, 0 rows affected |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Get function | |
''' | |
payload = {'key1': 'value1', 'key2': 'value2'} | |
r = requests.get("http://httpbin.org/get", params=payload) | |
print(r.text) | |
# 如果返回信息是json | |
print(r.json()) | |
''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def modify_permiss(self, path, name,R=True): | |
''' | |
change file or directory permission | |
:param name: linux user name\ | |
:param R: Recursive modify permission | |
:return: | |
''' | |
idshell = 'id %s'%(name) | |
code, output = self.execshell(idshell) | |
if 'No such' not in output: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
使用commdans执行shell命令 | |
这种方式不会创建独立进程去执行shell命令,即python程序退出,shell命令启动的程序也就退出了 | |
这种方式适合于短时任务,即不是后台进程型任务 | |
python2才会有 | |
''' | |
def execshell(self, shell): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def execshell(shell): | |
exit_status, output = commands.getstatusoutput(shell) | |
if int(exit_status) == 0: | |
print('%s execute success!'%shell) | |
else: | |
print('%s execute error: exit_status [%s] err [%s]' % (shell, str(exit_status), output)) | |
# if shell error , exit python program | |
exit() | |
return exit_status, output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_today(): | |
''' | |
Get today timestamp | |
:return: | |
''' | |
today = datetime.date.today() | |
today_timestamp = int(time.mktime(today.timetuple())) | |
now_timestamp = int(time.time()) | |
# yesterday = today - datetime.timedelta(days=1) | |
# yesterday_timestamp = int(time.mktime(yesterday.timetuple())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@debug | |
def sql2(self, sql): | |
def execsql2(db_con,cur,sql): | |
''' | |
if you first close the conn then use ping or any other operating, you | |
will get error about : err.InterfaceError("(0, '')"). | |
so , do any operate before the close operating | |
''' | |
#reconnect MySQL |