Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help Setting Up A CRONTAB File

Status
Not open for further replies.

mtorbin

Technical User
Nov 5, 2002
369
US
Hey alll,

I'd like to set up a CRONTAB file that would do the following on the FIRST day of every month:

1) Copy a file called ftpLog.txt to a new location and append something to its name, such as "_JAN" but would be specific to the previous month.
2) Open the old version of ftpLog.txt and completely clean it out.

So far, this is what I have:

0 0 1 * * (cp /var/ /var/ rm /var/ mk /var/ chmod a+wr ftpLog.txt) >/dev/null 2>&1

Any help would be most appreciated.

- MT
 
I find it's better to put those commands into a script, then keep the crontab entry simple...
Code:
0 0 1 * * /path_to/move_ftpLog.sh >> /path_to/move_ftpLog.log 2>&1
That makes it easier to change the commands it's doing later on. Just modify the script.

Hope this helps.
 
create a script to do the tasks:


move_log.sh for instance: This script could have commands:
Code:
#!/usr/bin/bash
cp /var/[URL unfurl="true"]www/cgi-bin/ftpLog.txt[/URL] /var/[URL unfurl="true"]www/cgi-bin/ftpLog_`date[/URL] +%b`.txt
rm /var/[URL unfurl="true"]www/cgi-bin/ftpLog.txt[/URL]

Then

$ crontab -e

59 11 1 1-12 * ~/move_log.sh >/dev/null 2>&1
 
Sorry actually I was trying to set it up to run on the last minute of the month so that you can use the date command.

So you can either change the first 2 values to 00 00 and live with the Month being the new month name, or you have to do something to minus the month (not too hard).
 
This would be first second of each month:

0 0 0 1-12 *

=)
 
Something like this...
Code:
#!/bin/ksh

set -A PREV Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov

cp /var/[URL unfurl="true"]www/cgi-bin/ftpLog.txt[/URL] /var/www/cgi-bin/ftpLog_${PREV[$(date '+%m')]}

:> /var/[URL unfurl="true"]www/cgi-bin/ftpLog.txt[/URL]
Then the crontab entry is...
Code:
0 0 1 * * /path_to/move_ftpLog.sh >> /path_to/move_ftpLog.log 2>&1
It will run right at midnight (plus or minus cron's clock resolution), and have the previous month's abbreviation in the name of the file.

Hope this helps.
 
Oops, forgot I was in a Linux forum. Ignore my script unless you have [tt]ksh[/tt] or [tt]pdksh[/tt].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top