1.
[root@yyjk templates]# cat displayexecssh.html
<html>
<head>
<title>运维平台</title>
<link rel="stylesheet" type="text/css" href="/static/Css/Monitor/displayexecssh.css">
<link rel="stylesheet" type="text/css" href="/static/Css/Public/header.css">
<link rel="stylesheet" type="text/css" href="/static/Css/Public/menu.css">
</head>
<body>
<include file="Public:header"/>
<div class="content">
<include file="Public:menu"/>
<div class="con fl">
<div id="condition">
<label class="condition">主机IP</label><input type="text" name="hostip" class="equipment_sz1">
<label class="condition">用户名</label><input type="text" name="hostuser" class="equipment_sz2">
<label class="condition">密码</label><input type="password" name="hostpass" class="equipment_sz3">
<br />
<br />
<label class="condition">命令</label><textarea id="command" class="equipment_sz4"></textarea>
<!--<label class="condition">保存的文件名</label><input type="text" name="exportname" class="equipment_sz6">-->
<br />
<br />
<input type="submit" value="执行" class="equipment_search_btn es_1">
<!--<input type="submit" value="组查找" class="equipment_search_btn es_2">-->
</div>
<table class="gridtable">
<tr>
<th>"output"</th>
</tr>
</table>
</div>
</div>
</body>
<script type="text/javascript" src="/static/Js/jquery-2.2.2.min.js"></script>
<script type="text/javascript" src="/static/Js/Monitor/displayexecssh.js"></script>
<script type="text/javascript" src="/static/Js/Public/ajax.js"></script>
</html>
2. css样式
.con .equipment_sz6{
200px;
height: 25px;
}
.con .equipment_sz4{
align:"top";
1000px;
height: 300px;
}
.con .equipment_sz1{
align:"top";
200px;
height: 30px;
}
.con .equipment_sz2{
align:"top";
150px;
height: 30px;
}
.con .equipment_sz3{
align:"top";
150px;
height: 30px;
}
def connect(
self,
hostname,
port=SSH_PORT,
username=None,
password=None,
pkey=None,
key_filename=None,
timeout=None,
allow_agent=True,
look_for_keys=True,
compress=False,
sock=None,
gss_auth=False,
gss_kex=False,
gss_deleg_creds=True,
gss_host=None,
banner_timeout=None,
auth_timeout=None,
gss_trust_dns=True,
passphrase=None,
):
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.55.243', username = 'root', password = 'P@ssw0rd', timeout = 5)
cmd = 'nohup /csdp/charge_launcher-1.0-release/bin/run.sh > /csdp/charge_launcher-1.0-release/bin/nohup.out 2>&1 &
'
password= 'P@ssw0rd'
stdin, stdout, stderr = ssh.exec_command( cmd )
##stdin, stdout, stderr = ssh.exec_command('sudo -S %s
' % cmd )
##stdin.write('%s
' % password)
##stdin.flush()
print "------------------------"
##print stdout.readlines()
##print stderr.read()
print "------------------------"
cmd = 'pwd'
stdin, stdout, stderr = ssh.exec_command(cmd )
print stdout.readlines()
ssh.close()
3.js 直接把执行返回内容写入到表格
$(function(){
var _hostip= $("input[name='hostip']");
var _hostuser= $("input[name='hostuser']");
var _hostpass= $("input[name='hostpass']");
var _command= $("#command");
var _ip_bt = $(".content .con #condition .es_1");
_ip_bt.on('click',function(){
var data={};
data.hostip=_hostip.val();
data.hostuser=_hostuser.val();
data.hostpass=_hostpass.val();
data.command=_command.val();
var successfn = function(jdata){
var _HTML="<tr><th>数据 </th></tr>";
$(".gridtable").empty();
/*var _HTML="<tr><th>数据 </th></tr>";*/
$.each(jdata,function(i,val){
_HTML=_HTML+"<tr><td>"+jdata[i]+"</td></tr>"
});
$(".gridtable").html(_HTML);
};
var errorfn = function(){
alert("数据获取出错");
};
$.ajax({
type: "get",
data: data,
url: "/api/commandssh",
dataType: "json",
success: function(d){
successfn(d);
},
error: function(e){
errorfn(e);
}
});
});
}
)