-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathssh.c
53 lines (50 loc) · 1.23 KB
/
ssh.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "examples_common.h"
int sshcmd(MYSQL_ROW rows,char *argv1){
ipinfo iplist;
// iplist动态分配内存
if ((iplist=malloc(sizeof(struct iplist))) == NULL)
{
fprintf(stderr, "iplist结构动态分配内存错误\n");
exit(1);
}
// ip信息分别赋值
iplist->ip=rows[1];
iplist->user=rows[2];
iplist->pawd=rows[3];
iplist->port=rows[4];
iplist->cmd=argv1;
// 执行命令
if (libssh(iplist)<0)
{
fprintf(stderr, "执行失败,请检查\n");
return -1;
}
return 0;
}
int main(int argc, char **argv)
{
MYSQL_RES *res;
MYSQL_ROW rows;
// 命令行
if (argc != 2)
{
fprintf(stderr, "请使用: ./ssh 命令\n");
return -1;
}
// 查询数据库
char *str="select * from iplist";
if ((res=query_mysql(str)) == NULL)
{
fprintf(stderr, "数据库结果集返回错误\n");
return -1;
}
// 获取结果集内容
while((rows=mysql_fetch_row(res))){
if (sshcmd(rows,argv[1]) < 0)
{
fprintf(stderr, "执行命令前的分配信息失败,请检查\n%s 执行失败\n",rows[1]);
return -1;
}
}
return 0;
}