#include #include #include #include #include "cmdline.h" using namespace std; int main(int argc, char * argv[]){ gengetopt_args_info args_info; if(cmdline_parser(argc, argv, &args_info) != 0){ cout << "Error with argument parser"; return 4; } string directory = "/tmp/check_smb_usedspace/0/"; string tempfile = "value.tmp"; string command = "mkdir -p "; command += directory; command += "mnt/ ; sudo "; command += "PASSWD=\""; command += args_info.password_arg; command += "\" /sbin/mount.cifs "; command += args_info.share_arg; command += " "; command += directory; command += "mnt/"; if(args_info.user_given){ command += " -o user="; command += args_info.user_arg; } command += "&& df | grep "; command += directory; command += "mnt"; command += "| awk '{ print($3) }' > "; command += directory; command += tempfile; command += " && sudo /bin/umount "; command += directory; command += "mnt/"; system(command.c_str()); string absolutepath; absolutepath = directory; absolutepath += tempfile; ifstream f(absolutepath.c_str()); char c='0'; string snombre(""); while(f.good() && c!='\t'){ c=f.get(); if(f.good() && c!='\t'){ snombre.append(sizeof(char), c); } } f.close(); command = "rm -R "; command += directory; system(command.c_str()); int inombre = atoi((char *) snombre.c_str()); if(inombre>=args_info.critical_arg){ cout << inombre << " kilo-octets, alerte !" << endl; cmdline_parser_free(&args_info); return 2; }else if(inombre>=args_info.warning_arg){ cout << inombre << " kilo-octets, warning !" << endl; cmdline_parser_free(&args_info); return 1; }else{ cout << inombre << " kilo-octets, ok !" << endl; cmdline_parser_free(&args_info); return 0; } cmdline_parser_free(&args_info); return 3; }