A Command Line Scheduler
Originally published on: Wed, 12 Aug 2009 02:28:54 +0000
In the post Throwaway Software: HangUp, I discussed creating a small utility due to customer demand that I thought was just a nice-to-have item to complement my other offerings. HangUp surprised me with the money that it brought in as did another program created the same day; TSched, the tiny command-line scheduler.
TSched employed a simple command-line syntax:
General format:
TSched [TSched options] [command options]
Where valid TSched options are:
-runat HH:MM
The above option executes a given command at the time
specified. Time must be specified in military 24-hour
format ( 6:05 p.m. is specified as 18:05 ).
-waituntil HH:MM
This option simply pauses until the specified time.
-quiet
This option suppresses the running status message.
The regular monthly sales from TSched were not noteworthy. Gross sales reached a total of $100 via my credit-card processor from 1999 to 2007 when the last copy was sold. Not monumental. However, TSched did attract the attention of a company who sold training software on CD. They paid me around $3,000 for an unlimited redistribution license with their training CD's.
Like HangUp, the overall amount of money I made on the product far outweighed the effort it took to write.
// TSched
// Tiny command-line scheduler
//
// License: MIT / X11
// Copyright (c) 1999. 2009 by James K. Lawless
// jimbo@radiks.net http://www.radiks.net/~jimbo
// http://www.mailsend-online.com
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
int __argc;
char ** __argv;
char stopTime[9];
char cmpTime[9];
int bWait=0;
int bRun=0;
int bQuiet=0;
char cmdline[1024];
void load_cmd_line();
int hasSpaces(char *);
void syntax();
int main(int argc,char **argv) {
printf("TSCHED - Tiny Scheduler v1.05\n");
printf("Copyright (c) 1999, 2009 by Jim Lawless\n");
if( __argc < 3 ) {
syntax();
Sleep(2000);
exit(1);
}
load_cmd_line();
for(;;) {
_strtime(cmpTime);
if( !bQuiet) {
printf("Waiting until %s current time is %s\r",
stopTime,cmpTime);
}
cmpTime[5]=0;
if( !strcmp(cmpTime,stopTime)) {
if(!bQuiet) {
if( bRun ) {
printf("\nLaunching %s\n",cmdline);
}
}
if( bRun ) {
system(cmdline);
}
break;
}
Sleep(500);
}
if( !bQuiet ) {
printf("\nExiting.\n");
}
exit(0);
}
void load_cmd_line() {
int i;
for(i=1;i<__argc;i++) {
if( *__argv[i] == '-' ) {
if( !stricmp(__argv[i],"-runat")) {
bRun=1;
if( strlen( __argv[i+1]) != 5 ) {
fprintf(stderr,"\aError! Time format is HH:MM!");
exit(1);
}
strcpy(stopTime,__argv[i+1]);
i++;
continue;
}
else
if( !stricmp(__argv[i],"-waituntil")) {
bWait=1;
if( strlen( __argv[i+1]) != 5 ) {
fprintf(stderr,"\aError! Time format is HH:MM!");
exit(1);
}
strcpy(stopTime,__argv[i+1]);
i++;
continue;
}
else
if( !stricmp(__argv[i],"-quiet")) {
bQuiet=1;
continue;
}
else {
break;
}
}
else {
break;
}
}
*cmdline=0;
for(;i<__argc;i++) {
if( hasSpaces(__argv[i] )) { // wrap in quotes
strcat(cmdline,"\"");
strcat(cmdline,__argv[i]);
strcat(cmdline,"\"");
}
else {
strcat(cmdline,__argv[i]);
}
if( (i+1) < __argc) {
strcat(cmdline," ");
}
}
if( !(bRun ^ bWait )) {
syntax();
exit(1);
}
}
int hasSpaces(char *s)
{
while(*s) {
if( (*s==' ')||(*s=='\t')) {
return(1);
}
s++;
}
return(0);
}
void syntax() {
printf("\nSyntax:\n TSched [TSched options] [command arguments ]\n");
printf( "\nValid TSched options:\n");
printf(" -runat HH:MM Execute command at specified time.\n");
printf(" -waituntil HH:MM Just wait until specified time ( no \n");
printf(" commands are executed.\n");
printf(" -quiet Suppress status messages.\n\n");
printf("Time (HH:MM) values must be entered in \"military time\" format.\n");
printf("( 6:05 p.m. would be specified as 18:05. )\n");
}
The source and EXE files for TSched can be found here.
http://www.mailsend-online.com/wp/tsched.zip
Unless otherwise noted, all code and text entries are Copyright ©2009 by James K. Lawless
Save to del.icio.us
Save to StumbleUpon
Digg it
Save to Reddit
Share on Facebook
Share on Twitter
More bookmarks