#include <stdio.h>
#include <stdlib.h>
int desat(int val)
{
int ret_val = 10;
int z;
for(z=1;z<val;z++)
ret_val = 10 * ret_val;
if(val==0)
ret_val = 1;
if(val==1)
ret_val = 10;
return(ret_val);
}
int main(void)
{
int cntr;
FILE *pipe_fp;
FILE * pFile;
int c,i;
int n = 0;
int ccomp[4]={0,0,0,0};
int cchar = 0;
int start = 0;
int track[10];
int counter = 0;
int vysledok = 0;
/* Create one way pipe line with call to popen() */
if (( pipe_fp = popen("/sbin/logsave /home/aquafishnet/crons/out.text uptime", "w")) == NULL)
{
perror("popen");
exit(1);
}
/* Close the pipe */
pclose(pipe_fp);
pFile=fopen ("/home/aquafishnet/crons/out.text","r");
if (pFile==NULL) perror ("Error opening file");
else
{
do
{
c = fgetc (pFile);
if(start==1)
{
if((c>=48)&&(c<=57))
{
counter++;
track[counter] = c-48;
}
else
{
start = 0;
}
}
for(i=2;i<=4;i++)
ccomp[(i-1)] = ccomp[i];
ccomp[4] = c;
if((ccomp[1]==103)&&(ccomp[2]==101)&&(ccomp[3]==58)&&(ccomp[4]==32))
start = 1;
}
while (c != EOF);
fclose (pFile);
}
// printf("\n load:");
for(i=counter;i>=1;i--)
vysledok = vysledok + (track[i]*desat((counter-i)));
if(vysledok>5)
{
if (( pipe_fp = popen("/sbin/logsave /home/aquafishnet/crons/out_restart.text /etc/rc.d/init.d/httpd restart", "w")) == NULL)
{
perror("popen");
exit(2);
}
/* Close the pipe */
pclose(pipe_fp);
}
return(0);
}
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main ()
{
FILE *pipe_fp;
time_t seconds0, seconds1;
int vysledok;
seconds0 = time (NULL);
/* Create one way pipe line with call to popen() */
if (( pipe_fp = popen("/sbin/logsave /home/aquafishnet/crons/out_self.text wget http://10.0.0.1/myfile.php --delete-after --timeout=10 --tries=1", "w")) == NULL)
{
perror("popen");
exit(1);
}
/* Close the pipe */
pclose(pipe_fp);
seconds1 = time (NULL);
// printf ("1: %d \n", seconds0);
// printf ("2: %d \n", seconds1);
vysledok = seconds1 - seconds0;
if(vysledok>9)
{
if (( pipe_fp = popen("/sbin/logsave /home/aquafishnet/crons/out_restart.text /etc/rc.d/init.d/httpd restart", "w")) == NULL)
{
perror("popen");
exit(2);
}
/* Close the pipe */
pclose(pipe_fp);
}
// printf("%d",vysledok);
return 0;
}
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main ()
{
FILE *pipe_fp;
time_t seconds0, seconds1;
int vysledok;
int vysledokn;
while(1==1)
{
seconds0 = time (NULL);
if (( pipe_fp = popen("wget http://www.google.com --delete-after --timeout=10 --tries=1", "w")) == NULL)
{
perror("popen");
exit(1);
}
pclose(pipe_fp);
seconds1 = time (NULL);
vysledok = seconds1 - seconds0;
vysledokn = 1;
if(vysledok>9)
{
vysledokn = 0;
}
if(vysledokn==1)
{
seconds0 = time (NULL);
if (( pipe_fp = popen("wget http://www.aqua-fish.net/show.php?h=discusfish --delete-after --timeout=10 --tries=1", "w")) == NULL)
{
perror("popen");
exit(1);
}
pclose(pipe_fp);
seconds1 = time (NULL);
vysledok = seconds1 - seconds0;
if(vysledok>9)
{
if (( pipe_fp = popen("smplayer /home/janhvik/Desktop/temp/c/alarm.wav -close-at-end", "w")) == NULL)
{
perror("popen");
exit(2);
}
pclose(pipe_fp);
}
}
sleep(30);
}
return 0;
}
gcc c_source.c -o script.out
March 2, 2010
©Jan Hvizdak 2009, all rights reserved
Document last modified on Fri Jun 11 1:38:16 MDT 2010.