/* This program calls the Encoder program at 1pm and 9pm everyday. It ftps the resulting file to unix */ #include #include #include #include #include int checkEndTime(int endHour, int endMin); int get_hour(); int get_minute(); int get_second(); int get_day(); int get_month(); int main(int argc, char *argv[]) { FILE *ftp_text; int counter,end_hour,end_minute,lastminute=0; int end,current_day,current_month=0; char thecommand[20]; counter=0; end=0; current_day=get_day(); current_month=get_month(); printf("here it is (%d)(%d) \n",current_day,current_month); while(end == 0) { end_hour=get_hour(); end_minute=get_minute(); current_day=get_day(); if(end_hour == 12 && end_minute == 58) { printf("Encoding Afternoon [%d][%d]\n",end_hour,end_minute); sprintf(thecommand,"encode %d_1pm.mpg 13 30",current_day); system(thecommand); if ((ftp_text = fopen("thefiles.scr","w")) == NULL) { printf("Cannot open the ftp textfile thefiles.scr \n\n"); exit(1); } fprintf(ftp_text,"open myserver.aserver.ie \n"); fprintf(ftp_text,"myusername\n"); fprintf(ftp_text,"mypassword\n"); fprintf(ftp_text,"cd /elpico6/video/processing/initialEncoderDir/ \n"); fprintf(ftp_text,"lcd e:/video \n"); fprintf(ftp_text,"bin \n"); fprintf(ftp_text,"put %d_1pm.mpg\n",current_day); fprintf(ftp_text,"bye \n"); fclose(ftp_text); system("ftp -s:thefiles.scr"); sprintf(thecommand,"del %d_1pm.mpg",current_day); system(thecommand); } if(end_hour == 20 && end_minute == 58) { printf("Encoding Evening [%d][%d]\n",end_hour,end_minute); sprintf(thecommand,"encode %d_9pm.mpg 21 30",current_day); system(thecommand); if ((ftp_text = fopen("thefiles.scr","w")) == NULL) { printf("Cannot open the ftp textfile thefiles.scr \n\n"); exit(1); } fprintf(ftp_text,"open shasta.compapp.dcu.ie \n"); fprintf(ftp_text,"myusername\n"); fprintf(ftp_text,"mypassword\n"); fprintf(ftp_text,"cd /elpico6/video/processing/initialEncoderDir/ \n"); fprintf(ftp_text,"lcd e:/video \n"); fprintf(ftp_text,"bin \n"); fprintf(ftp_text,"put %d_9pm.mpg\n",current_day); fprintf(ftp_text,"bye \n"); fclose(ftp_text); system("ftp -s:thefiles.scr"); sprintf(thecommand,"del %d_9pm.mpg",current_day); system(thecommand); } } // end main return 0; } int get_day() { long tt; struct tm *Tm; time(&tt); Tm = localtime(&tt); return Tm->tm_mday; } int get_month() { long tt; struct tm *Tm; time(&tt); Tm = localtime(&tt); return Tm->tm_mon; } int get_hour() { int continueText = 0; time_t timeInSec; struct tm *Tm; time(&timeInSec); Tm = localtime(&timeInSec); return Tm->tm_hour; } int get_minute() { int continueText = 0; time_t timeInSec; struct tm *Tm; time(&timeInSec); Tm = localtime(&timeInSec); return Tm->tm_min; } int get_second() { int continueText = 0; time_t timeInSec; struct tm *Tm; time(&timeInSec); Tm = localtime(&timeInSec); return Tm->tm_sec; } int checkEndTime(int endHour, int endMin) { int continueText = 0; time_t timeInSec; struct tm *Tm; time(&timeInSec); Tm = localtime(&timeInSec); if(Tm->tm_hour == endHour) { if(Tm->tm_min == endMin) { continueText = 1; } } // printf("[%d]:[%d]/[%d][%d] \n",endHour,endMin,Tm->tm_hour,Tm->tm_min); return continueText; }