New TECS Version Sept. 2001 M.Z.
This commit is contained in:
102
tecs/rstart.c
102
tecs/rstart.c
@@ -5,54 +5,17 @@
|
||||
#include <stdio.h>
|
||||
#include <netdb.h>
|
||||
#include "myc_str.h"
|
||||
#include "instr_hosts.h"
|
||||
|
||||
int rexec(char **host, int port, char *user, char *passwd, char *command, int *err_file_desc);
|
||||
|
||||
int wrtRd(int fd, char *cmd, char *res, int res_len) {
|
||||
int i, p, l, cnt;
|
||||
char buf[8192];
|
||||
struct timeval tmo;
|
||||
fd_set rmask;
|
||||
|
||||
if (cmd[0]!='\0') {
|
||||
l=send(fd, cmd, strlen(cmd), 0);
|
||||
if (l<0) return -1;
|
||||
}
|
||||
tmo.tv_sec=2;
|
||||
i=1;
|
||||
p=0;
|
||||
while (i>0 && p<sizeof(buf)-1) {
|
||||
FD_ZERO(&rmask);
|
||||
FD_SET(fd, &rmask);
|
||||
tmo.tv_usec=500000;
|
||||
i=select(fd+1, &rmask, NULL, NULL, &tmo);
|
||||
tmo.tv_sec=0;
|
||||
if (i>0) {
|
||||
l=recv(fd, buf+p, sizeof(buf)-p-1, 0);
|
||||
if (l<0) return -1;
|
||||
p=p+l;
|
||||
if (l==0) i=0;
|
||||
}
|
||||
}
|
||||
if (p >= res_len) p=res_len-1;
|
||||
buf[p]='\0';
|
||||
strcpy(res, buf);
|
||||
return p;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int port, i, j, l, fd;
|
||||
char *host, inst[32], cmd[256], buf[256], path[256];
|
||||
char *instrHosts[]={
|
||||
"DMC","lnsa05.psi.ch",
|
||||
"TOPSI","lnsa07.psi.ch",
|
||||
"SANS","lnsa10.psi.ch",
|
||||
"HRPT","lnsa11.psi.ch",
|
||||
"TRICS","lnsa13.psi.ch",
|
||||
"AMOR","lnsa14.psi.ch",
|
||||
"FOCUS","lnsa16.psi.ch",
|
||||
"ZOLLIKER","lnsa15.psi.ch"
|
||||
};
|
||||
char inst[32], cmd[256], host[256], user[64], pcod[64];
|
||||
char *hostp;
|
||||
struct tm tim;
|
||||
time_t t;
|
||||
|
||||
struct servent s;
|
||||
|
||||
s=*getservbyname("exec", "tcp");
|
||||
@@ -61,61 +24,28 @@ int main(int argc, char *argv[]) {
|
||||
printf("not enough arguments\n");
|
||||
return 0;
|
||||
}
|
||||
str_upcase(inst, argv[1]);
|
||||
str_copy(cmd, "\n");
|
||||
i=InstrHost(argv[1], inst, host, user, pcod, sizeof(inst), sizeof(host), sizeof(user), sizeof(pcod));
|
||||
if (i==0) {
|
||||
printf("unknown host/instrument\n");
|
||||
return -1;
|
||||
}
|
||||
str_copy(cmd, "");
|
||||
for (i=2; i<argc; i++) {
|
||||
if (0==strcmp(argv[i], "sics")) {
|
||||
str_append(cmd, "startsics\n");
|
||||
str_append(cmd, "bin/startsics\n");
|
||||
} else if (0==strcmp(argv[i], "tecs")) {
|
||||
str_append(cmd, "startecs\n");
|
||||
str_append(cmd, "bin/startecs\n");
|
||||
} else {
|
||||
printf("unknown server %s\n", argv[i]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
buf[0]='\0';
|
||||
host=NULL;
|
||||
for (i=0; i<sizeof(instrHosts)/sizeof(instrHosts[0]); i+=2) {
|
||||
if (0==strcmp(instrHosts[i], inst)) {
|
||||
host=instrHosts[i+1];
|
||||
} else if (0==strcmp(instrHosts[i+1], argv[1])) {
|
||||
host=argv[1];
|
||||
str_copy(inst,instrHosts[i]);
|
||||
}
|
||||
}
|
||||
if (0==strcmp(inst, "ZOLLIKER")) {
|
||||
str_copy(buf, "69kilo");
|
||||
str_copy(inst, "zolliker");
|
||||
} else if (host==NULL) {
|
||||
printf("unknown instrument: %s\n", argv[1]);
|
||||
return 0;
|
||||
}
|
||||
printf("login to %s\n", host);
|
||||
if (buf[0]=='\0') {
|
||||
str_copy(buf, inst);
|
||||
str_append(buf, "LNS");
|
||||
}
|
||||
fd=rexec(&host, s.s_port, inst, buf, "rlogin 0", &i);
|
||||
hostp=host;
|
||||
fd=rexec(&hostp, s.s_port, user, pcod, cmd, &i);
|
||||
if (fd<0) {
|
||||
perror("rexec"); return -1;
|
||||
}
|
||||
|
||||
if (wrtRd(fd, "\n", buf, sizeof(buf)) < 0) goto Error;
|
||||
if (wrtRd(fd, "\n", buf, sizeof(buf)) < 0) goto Error;
|
||||
if (wrtRd(fd, "\n", buf, sizeof(buf)) < 0) goto Error;
|
||||
if (wrtRd(fd, cmd, buf, sizeof(buf)) < 0) goto Error;
|
||||
printf("%s\n", buf);
|
||||
l=1;
|
||||
while (l>0) {
|
||||
if (l=wrtRd(fd, "", buf, sizeof(buf)) < 0) goto Error;
|
||||
printf("%s", buf);
|
||||
}
|
||||
printf("\n");
|
||||
i=10;
|
||||
while (i>0 && wrtRd(fd, "logout\n", buf, sizeof(buf)) >= 0) {
|
||||
i--;
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
Error: perror("error in wrtRd"); return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user