update: tried print return value of system()
. if ssh failed, return 65280, if succeed ,it returns 0.
i want ssh machine laptop,i write c program, access machine , touch file on machine. network not stable or maybe machine down. therefore, ssh
failed. how know ssh
failed in program ? sometime ssh
machine succeed, touch file failed, how distinguish them in c program? how know shell command failed because of ssh
failed not touch
? don't want stare @ screen, want program check automatically.
here code: #include<stdio.h> #include<stdlib.h> #include<time.h> int main(int argc,const char *argv[]) { while(1) { system("ssh liulyix@localhost -p 22210 'touch script/rebooter.sh'"); sleep(5); } }
read man page system.
the proto type is
int system (constant char *command)
the return values -1 system unable execute command because of fork failure. @ man page execve , @ error number may raised. these errnos reasons why system return -1.
all other returns ed values exit code of command. 0 implies success, other values imply command crashed exit_failure.