matze77 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks! The Situation:
We got a Linux System with an old NT-Basic application that writes a Logfile (a simple text file) to a given path.
My task ;-) is now to a) "rotate" that logfile (its small so i could store a week or more till overwriting the first log) and
b) copy the logfile to a samba share on the same machine where it should be
c)copied (this could be a windows machine?) to a NAS share from which it could be accessed by some people (the bosses) My Problem: The Linux box is a SUSE 8.2 with Perl 5.8 and no cpan (I am not allowed to change that)
cause of compatibility issues with the systems and maybe the archive program which relies on the give Perl version.
The windows system i could change so maybe if it is best done with usage of modules i could do it here?
(SSH and ftp-access is possible so win-scp or simular tools could be used). Maybe you got a hint in which direction i should try to develop a solution?
Update: No Perl code i am afraid:
As i figured out the logfile is only produced during the daily backup job which is scheduled at night, so i solved it for the moment as i put a simple copy (shell #!/bin/sh) job in crontab which moves the file to the samba share. hint: crontab -e is different from /etc/crontab the sixth colon is not the username it starts with the command directly

/etc/crontab #min hour day month dow(day of week) user command 40 22 * * * root /usr/local/sbin/cplogb #users crontab (edit with crontab -e)the same thing without the userna +me in front of the command: 40 22 * * * /usr/local/sbin/cplogb
Update
hth maybe someone which didnt mess around with cron like me for some time ;-).
...

Thanks in Advance MH

Replies are listed 'Best First'.
Re: How to do a manual "logrotate" on a given file?
by ctilmes (Vicar) on Nov 24, 2009 at 13:28 UTC
    Check out logrotate. Usually installed on Linux systems by default.

      According to my SuSE Linux 8.2 Administration Guide, the logrotate program is provided.

      You don't necessarily need to use the system file /etc/logrotate.conf. You can instead use your own local config file, specific for your application, and just specify that config file on the command line. Personally, I would write a shell script (sorry, no perl) that runs from cron, which invokes logrotate and then does the copying you want. Run it just before the bosses get to work in the morning :-)

Re: How to do a manual "logrotate" on a given file?
by bruno (Friar) on Nov 24, 2009 at 14:06 UTC
      That doesn't work if the file is continuously being updated by another process (or processes), which is often the case with logfiles. It's only a solution if you are in full control over the single process that's updating the log file. Even if there are two instances of the same program log to the file, the given solution is going to fail.

        I think i give it a try afaik the "logfile" is produced at a given time once a day only so if its possible that the file isnt altered at that few seconds it is ok ... I think it might be a cron job, but i am searching for that ...

        Thanks in Advance MH
        I don't know much about concurrent access to files, but wouldn't locking the file solve this issue?

Re: How to do a manual "logrotate" on a given file?
by jethro (Monsignor) on Nov 24, 2009 at 13:36 UTC
    The tasks you mention sound rather trivial (some moving and copying of files), why would you need CPAN for that?

    Sure, it would be safer and cleaner with modules, but without modules is still easier than remote administering from a windows box (remember you might have to adapt some of the modules to do things remote, which would invalidate that "safe and clean").