Полезная информация

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 40.9 Checking and Removing Jobs Chapter 40
Delayed Execution
Next: 40.11 Send Yourself Reminder Mail
 

40.10 nextday, nextweekday: Tomorrow or Next Weekday

nextday
Before my UNIX systems had personal crontabs (40.12), I wanted a way to make an at job (40.3) repeat itself the next weekday (skipping Saturday and Sunday) or, sometimes, every day. Our at was simple-minded and didn't understand dates like now + 1 day. This script with two names, nextday and nextweekday, did the job. I called it from inside my at job, like this:



`...` 
% cat atjob
somecommand
sleep 60
at 2325 `nextweekday` < atjob

On Thursday, the result will be a command like at 2325 Friday atjob. On Friday, the command will be at 2325 Monday atjob; using nextday instead, the result would be at 2325 Saturday atjob.

The -n option returns a numeric weekday.

NOTE: This script only works with some versions of date. If your version doesn't understand format strings like +%format, install the date (51.10) from the CD-ROM.

You can install this script from the CD-ROM or from the online archive (52.7). If you get it from the archive, ask tar to install nextday and its other link:

% tar xvf archive.tar nextday nextweekday
x nextday, 1564 bytes, 4 tape blocks
nextweekday linked to nextday

The script tests the name it was called with, in $0, to decide which command to run.

- JP


Previous: 40.9 Checking and Removing Jobs UNIX Power ToolsNext: 40.11 Send Yourself Reminder Mail
40.9 Checking and Removing Jobs Book Index40.11 Send Yourself Reminder Mail

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System