Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #355008
    Rogier Koek
    Participant

    Simple one if you know unix…

    I need to mv a log file to another file on a daily basis. So I would like to automaticly rename the file to today’s date and this needs to be done every workday.

    Problems are: I don’t know if I can set mv to change the filename to a date (e.g. 010103.log) and I don’t know cron…

    If anybody can help out, I would be gratefull…

    #355127
    Admin
    Participant

    Rogier,

    You can do this! You’ll need to write a shell script to handle the rename/move bit, though. I recommend picking up a copy of [i:5306a32a42]Using csh & tcsh[/i:5306a32a42] (O’Reilly) if you aren’t familiar with the shell. Or, you could write the script in Perl or Python, too. Heck, you could probably write a compiled AppleScript to do it, too.

    Regardless, you’ll want the script to build a string with the current date?this will probably be easier to do in Perl or Python?and append it to a string representing the file name.

    Execute the mv shell command, giving it the old and new file names. That will move the file from the old to the new name. You may need to ‘touch’ the plain file so that the log daemon will pick up the name change, or send SIGHUP to the daemon process.

    Once you have the script created and working, you can add it to a cron job under your account. If you don’t already have a crontab, then create a file called “mycron.in” containing:[code:1:5306a32a42]#

    Logroller cron tab

    MAILTO=your_user_name

    #
    @daily * * * * path/to/script[/code:1:5306a32a42]

    then feed it into cron with crontab -u your_user_name mycron.in

    If you already have a crontab, you can append the @daily line by using crontab -e.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Comments are closed