23 int usage(
const char* errstr = 0)
25 if (errstr!=0) printf(
"Error: %s\n\n", errstr);
27 printf(
"Utility for execute commands on remote MBS node\n");
28 printf(
" mbscmd nodename [args] -cmd cmd1 [-cmd cmd2] [-cmd cmd3] ...\n");
29 printf(
"Arguments:\n");
30 printf(
" -logport number - port number of log channel (-1 - off, default 6007)\n");
31 printf(
" -cmdport number - port number of command channel (-1 - off, default 6019)\n");
32 printf(
" -prompter - connect to MBS prompter (same as -cmdport 6006)\n");
33 printf(
" -stat - enable reading of status record from port 6008 (default off)\n");
34 printf(
" -cmd mbs_command - MBS command to execute (can be any number)\n");
35 printf(
" -tmout time - timeout for command execution (default 5 sec)\n");
36 printf(
" -wait time - wait time at the end of utility (default 1 sec)\n");
38 return errstr ? 1 : 0;
42 int main(
int argc,
char* argv[])
44 if (argc<2)
return usage();
46 int logport(6007), cmdport(6019), statport(0);
47 double tmout(5.), waittm(1.);
49 std::vector<std::string> cmds;
53 if (strcmp(argv[n],
"-prompter")==0) { cmdport = 6006; }
else
54 if (strcmp(argv[n],
"-stat")==0) { statport = 6008; }
else
55 if ((strcmp(argv[n],
"-logport")==0) && (n+1<argc)) {
dabc::str_to_int(argv[++n], &logport); }
else
56 if ((strcmp(argv[n],
"-cmdport")==0) && (n+1<argc)) {
dabc::str_to_int(argv[++n], &cmdport); }
else
57 if ((strcmp(argv[n],
"-tmout")==0) && (n+1<argc)) {
dabc::str_to_double(argv[++n], &tmout); }
else
58 if ((strcmp(argv[n],
"-wait")==0) && (n+1<argc)) {
dabc::str_to_double(argv[++n], &waittm); }
else
59 if ((strcmp(argv[n],
"-cmd")==0) && (n+1<argc)) { cmds.push_back(argv[++n]); }
else
60 usage(
"Unknown option");
69 for (
unsigned n=0;n<cmds.size();n++)
70 ref.
MbsCmd(cmds[n], tmout);
bool Disconnect()
Release connection to the MBS node.
static MonitorHandle Connect(const std::string &mbsnode, int cmdport=6019, int logport=6007, int statport=6008)
Connect with MBS node.
bool MbsCmd(const std::string &cmd, double tmout=5.)
Execute MBS command.
int main(int argc, char *argv[])
int usage(const char *errstr=0)
void SetDebugLevel(int level=0)
bool str_to_double(const char *val, double *res)
Convert string to double value.
bool str_to_int(const char *val, int *res)
Convert string to integer value.