Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * exec command
- * Author: Stefano Viola ---> Esteban Sannin
- *
- *
- *
- *
- *
- */
- #include <stdio.h>
- #include "monitor.h"
- #include <time.h>
- int main(int argc, char *argv[], char *envp[]){
- //Genera la pagina html
- printf("Content-type: text/html\n\n"
- "<html>\n"
- "<head>\n"
- "<title>Monitoring Router</title>\n"
- "</head>\n"
- "<body>\n");
- stamp_command("Sistem:", "uname -a");
- stamp_command("SERVER WEB:", "env | grep SERVER_SOFTWARE | cut -f 2 -d=");
- stamp_command("Uptime:", "uptime");
- stamp_command("Memory:", "free");
- stamp_command("Disk usage:", "df");
- // stamp_command("ifconfig:", "ifconfig");
- stamp_command("prova:", "./pippo.sh");
- int i;
- for (i = 0; i < 1; i++){
- int first_value = stamp_rate("ifconfig wlan0 | grep 'Byte RX' | cut -f 2 -d: | awk {'print $1'}");
- sleep(2);
- int second_value = stamp_rate("ifconfig wlan0 | grep 'Byte RX' | cut -f 2 -d: | awk {'print $1'}");
- printf("\nfirst: %d second: %d\n", first_value, second_value);
- int difference = second_value-first_value;
- float rate = (difference/2)/1024;
- printf("Band Rate Download RX: %.2f\n\n",rate);
- }
- // stamp_command("ENV:", "env");
- printf("</body>");
- return 0;
- }
- int stamp_rate(char *string_command){
- int byte = command_number(string_command);
- return byte;
- }
- void stamp_command(char *string_title, char *string_command){
- printf("<p><b><font color='red'>%s</font></b></p>",string_title);
- printf("<pre>");
- command(string_command);
- printf("</pre><br>");
- }
- //test for read number
- //
- int command_number(char *command){
- FILE *fp;
- char line[256];
- int iRet = 0;
- int number_byte;
- fp = popen(command, "r");
- if (fp != NULL) {
- while (fgets(line, sizeof(line), fp)) {
- number_byte = atoi(line);
- }
- pclose(fp);
- iRet = 0;
- } else {
- iRet = -1;
- }
- return number_byte;
- }
- ///testing funzione per comandi da shell
- int command(char *command){
- FILE *fp;
- char line[256];
- int iRet = 0;
- fp = popen(command, "r");
- if (fp != NULL) {
- while (fgets(line, sizeof(line), fp)) {
- printf("%s", line);
- }
- pclose(fp);
- iRet = 0;
- } else {
- iRet = -1;
- }
- return iRet;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement