Chinaunix首页 | 论坛 | 博客
  • 博客访问: 786229
  • 博文数量: 109
  • 博客积分: 650
  • 博客等级: 上士
  • 技术积分: 1483
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-01 17:29
文章分类

全部博文(109)

文章存档

2016年(5)

2015年(21)

2014年(16)

2013年(38)

2012年(29)

分类: 系统运维

2012-05-22 16:37:40


点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <float.h>
  3. #include <time.h> //time_t
  4. #include <signal.h>
  5. #include <sys/types.h> //fork
  6. #include <unistd.h> //fork
  7. #include <sys/types.h> //open
  8. #include <sys/stat.h> //open
  9. #include <fcntl.h> //open
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <list>
  13. #include <string>
  14. #include <string.h>
  15. #include <unistd.h>
  16. #include <sys/types.h>
  17. #include <iostream>
  18. #include <float.h>
  19. #include <sys/types.h>
  20. #include <sys/stat.h>
  21. #include <time.h>
  22. #include <errno.h>
  23. #include <time.h>
  24. #include <sys/types.h>
  25. #include <dirent.h>
  26. #include <unistd.h>
  27. #include <fcntl.h>
  28. #include <fstream>
  29. #include <sys/param.h>


  30. using namespace std;

  31. string BSC_PATH,BSC_NAME;
  32. int BSC_NAME_LENGTH;

  33. int main(int argc,char **argv)
  34. {
  35. struct sigaction act;
  36. int error,in,out;
  37. time_t now;
  38. int memory;
  39. long int M15=0;
  40. FILE* f;
  41. char buffer[1024]={0};
  42. while(1)
  43. {
  44.     time_t timep,timers;
  45.     struct tm tblock;
  46.     struct tm tnow;
  47.     struct tm files_wait;

  48.     time(&timep);
  49.     printf("%s",asctime(gmtime(&timep)));
  50.     tnow= *localtime(&timep);

  51.     int NowHour=0,NowMin=0,Mon=0,Day=0,Yers=0;
  52.     Yers=tnow.tm_year+1900;
  53.     Mon=tnow.tm_mon+1;
  54.     Day=tnow.tm_mday;
  55.     NowHour=tnow.tm_hour;
  56.     NowMin=tnow.tm_min;
  57.     int FIAG = 0;
  58.     cout<<"NOW time is Year:"<<Yers<<"-"<<Mon<<"-"<<Day<<" "<<NowHour<<":"<<NowMin<<endl;
  59.     if ( NowMin == 59 )//|| (NowHour == 15 && NowMin == 29) || (NowHour == 23 && NowMin == 59))
  60.     {
  61.      f=popen("((ss=`date +%s/900*900`));echo $ss","r");
  62.      if (f==NULL)
  63.      {
  64.          return 1;
  65.      }
  66.      if (fscanf(f,"%ld",$M15)!=1)
  67.      {
  68.          return 2;
  69.      }
  70.      cout<<M15<<endl;
  71.      sprintf(buffer,"Run.sh %ld >/dev/null 2>&1",M15)
  72.        system(buffer);
  73.        cout<<"end"<<endl;
  74.        string CMD = "date >> /home/omcbo/RunRLDCPII.sh.log";
  75.        system(CMD.c_str());
  76.        sleep(60);
  77.     }
  78.     else
  79.     {
  80.         sleep(50);
  81.     }
  82.     sleep(10);
  83. }

  84. exit(0);
  85. }


点击(此处)折叠或打开

  1. $ cat test.c

  2. #include <stdio.h>

  3. int main()

  4. {

  5.         FILE* f;

  6.         int i;

  7.         f = popen("echo 123456","r");

  8.         if(f==NULL)

  9.                 return 1;

  10.         if(fscanf(f,"%d",&i)!=1)

  11.                 return 2;

  12.         printf("%d\n",i);

  13.         return 0;

  14. }

  15. $ gcc test.c

  16. $ ./a.out

  17. 123456



  18. char buffer[1024] = { 0 };
  19. sprinft(buffer,"shutdown /s /t %d",n);
  20. system(buffer);
  21. system函数需要字符串首地址作为参数,
  22. 所以就把命令和参数都保存到字符型数组中再把数组首地址传进去就行了

阅读(1061) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~