ºìÁªLinuxÃÅ»§
Linux°ïÖú

linux ϱȽÏÓÐÓõÄÒ»¸öC³ÌÐòÀý×Ó

·¢²¼Ê±¼ä:2008-03-24 20:52:15À´Ô´:ºìÁª×÷Õß:rchivedz
½ñÌì°ïÅóÓÑ×öÁËÒ»¸ölinuxϵĶ¨Ê±½ÓÊÜÎļþ³ÌÐò£¬¸Ð¾õ³ÌÐòСµ«ÊǺܵäÐÍ¡£ºÇºÇ£¬³¤Ê±¼äûÔÚlinuxϱà³Ì£¬¸Ð¾õͦ²»Êæ·þµÄ£¬¿ÉÄܺöàÈ˶¼Óöµ½Õ⼸¸öÎÊÌ⣬¶ÔÄãÓаïÖúÎҾ͸ßÐËÁË¡£

ÐèÒªÍê³ÉµÄÎÊÌ⣺

1¡¢Ã¿Ì춨ʱÔÚÍí¼ä11µã50 ½ÓÊÜ3ÌìÇ°ËûÃǵ¥Î»Ï·¢µÄÊý¾Ý

½ÓÊܲ¿·ÖÓиöSHELL¡£½Ð JS.sh

2¡¢SHELLÐèÒª´«ÈëµÄÊÇ£º20080301¸ñʽµÄÊý¾Ý

³ÌÐòÈçÏ£º

ÒýÓÃ:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int rqz(yy,mm)
{switch(mm)
{
case 1:return 31;break;
case 2:return 28+(yy%400==0||(yy%4==0&&yy%100!=0));break;
case 3:return 31;break;
case 4:return 30;break;
case 5:return 31;break;
case 6:return 30;break;
case 7:return 31;break;
case 8:return 31;break;
case 9:return 30;break;
case 10:return 31;break;
case 11:return 30;break;
case 12:return 31;break;
}
}

**ÒÔÉÏÊǼÆËãÈÕÆÚ**
void init_daemon(void)
{
int childpid;
int i;
#ifdef SIGTTIN
signal(SIGTTIN,SIG_IGN);
#endif

#ifdef SIGTTOU
signal(SIGTTOU,SIG_IGN);
#endif

#ifdef SIGTSTP
signal(SIGTSTP,SIG_IGN);
#endif
if((childpid=fork())<0)
printf("fork err");
else if(childpid>0)
exit(0);

setsid();

signal(SIGHUP,SIG_IGN);
if(childpid=fork())
exit(0);
else if(childpid< 0)
exit(1);

for(i=0;i< NOFILE;i++)
close(i);
chdir("/home/ghz1989");
umask(0);
return;
}

ÉÏÃæÊÇÊØ»¤½ø³Ì¡£

void init_daemon(void);
main()
{
FILE *fp,*fp1;
time_t timep;
struct tm *p;
int sj;
int fz;
int rqj;
int rq;
int yyy;
int mmm;
char hh[5];
char rqh[3];
char rqh0[3];
char yyyc[5];
char mmmc[3];
char dddc[3];
char ymdc[9];
static char bbjsc1[13]="./js.sh ";
char bbjsc[13];

init_daemon();


while(1)
{
sleep(50);

time(&timep);
p=gmtime(&timep);
sj=p->tm_hour+8;
rqj=p->tm_mday-3;
fz=p->tm_min;


if (rqj<1)
{
yyy=p->tm_year+1900;
mmm=p->tm_mon;
rq=rqz(yyy,mmm)+rqj;
}

ÅжÏ3ÌìÇ°µÄÈÕÆÚ£¬ºÇºÇ£¬µ½Ã¿ÔÂ1¡¢2¡¢3ºÅ¡£ÒªÅжϣ¬LINUX C ¾ÍÊÇÕâÑùÂé·³£¬VBÀïÃæÖ±½ÓDATE-3¾ÍºÃÁË¡£

if (rqj>=1)
{
rq=rqj;
yyy=p->tm_year+1900;
mmm=p->tm_mon+1;
}
sprintf(rqh,"%d",rq);

if (rq<10)
{
strcpy(rqh0,"0");
strcat(rqh0,rqh);
strcpy(rqh,rqh0);
}

ÅжÏÊDz»ÊÇСÓÚ10ºÅ
sprintf(yyyc,"%d",yyy);
sprintf(mmmc,"%d",mmm);

if (mmm<10)
{
strcpy(mmm0,"0");
strcat(mmm0,mmmc);
strcpy(mmc,mmm0);
}


strcpy(dddc,rqh);
strcpy(ymdc,"\0");
strcpy(ymdc,yyyc);
strcat(ymdc,mmmc);
strcat(ymdc,dddc);

if((sj==23)&&(fz==50))
{
if((fp=fopen("test.log","a")) >=0)
{
fprintf(fp,"receiving date at %s\n",ymdc);
fclose(fp);
}
strcpy(bbjsc,"\0");
strcpy(bbjsc,bbjsc1);
strcat(bbjsc,ymdc);
system(bbjsc);

}
}
}


UNIX INUX CÓïÑÔÕæµÄÌ«Âé·³ÁË£¡
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ