• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to set a one time cron programmatically using - "at" command  RSS feed

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have quite a situation. We have a process in place that could invoke a shell script whenever a file gets dropped to a particular directory.

In my case, I just cannot blindly kick off the process when a file is there. I got to check if the a date field in the file is the current date. If so, process needs to be run now. The date could be a future date too. In that case, I need to set up a one cron job to run that process on the date specified in the file.

I tried to play with "at" command. I was successful on the unix command prompt. This is what I typed at the prompt

$ at 1140
at$ ls -l > list
at$^D

I got the message "commands will be executed using /bin/ksh
job 1101314700.a at Wed Nov 24 11:40:00 2004"

I checked for the existence of the file "list" at 11:41 and found it. So, the one time cron was successful.

I want to do similar thing inside a script. I wrote a test script, test.sh

at 1150
ls -l > output
Ctrl-d

I saved the file. Not sure what needs to be done from this point. In realtime, another process will create this file and has to make this one as a one time cron entry.

Any pointers/help is greatly appreciated. Any unix system administartors there?

Thanks
[ November 24, 2004: Message edited by: Pri Vij ]
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pri Vij:

I want to do similar thing inside a script. I wrote a test script, test.sh

at 1150
ls -l > output
Ctrl-d


Hi Pri,

It should be:


Not tested, but that's the idea. Your script didn't work did it?
If you want to know what it is about, google for "here document".

Petr
 
Priyaa V Kumar
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks so much for your reply. I used your tip and wrote my command to be executed using "at" into another file and called it in my script and it worked.

Here's what I tried...

#! /bin/ksh
INPUT_FILE=/myhome/data/testing.txt
VAR_LINE=""
DT=""
CURRENT_DATE=""


VAR_LINE=`head -1 $INPUT_FILE`
echo $VAR_LINE

DT=`echo $VAR_LINE|cut -d' ' -f11-11`
echo $DT

CURRENT_DATE=`date +%m\/%d\/%Y`
echo $CURRENT_DATE

if test $DT != $CURRENT_DATE ; then
echo "Dates are not equal"
at 1105 < temp.sh > hey.log
exit
fi


+++++++++++++++++++++++++++++

commands will be executed using /bin/ksh
job 1101488580.a at Fri Nov 26 12:03:00 2004
 
Saloon Keeper
Posts: 18800
74
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For scripts, I think the following works:

at 09:00 -c myscript

Check the man page to be sure. "Here" scripts are good if you don't have a prewritten file and you want to enter it on the fly. Another variant is to do something like:

echo 'mail myself <nagnote.txt' | at 21:30
[ November 29, 2004: Message edited by: Tim Holloway ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!