0

The following line which include into the cronjob.

18,36,54 * * * * /usr/bin/perl  /home/folder.my_perl.pl >> out.log 2>> error.log

The error.log file will write all the errors and out.log file write all the output statement. I want to know that, If the size of both file is exceed then, System automatically create another or we have to maintain it manually?

Pranay
  • 5
  • 6
  • Why should the system create new ones? I/O redirection is not something *smart*. You only say: *write file description X to file Y.* – Willem Van Onsem Jun 01 '15 at 11:19
  • @CommuSoft Yes, but like mysql and other environment create atomatically error.log files and commpress old one. As like,can we do it ? – Pranay Jun 01 '15 at 11:25

2 Answers2

0

You will have to maintain it "manually". The filestystem does not have any house-keeping mechanisms which would monitor the size/age of files being created.

You can use logrotate to simplify the administration. This is a program which is usually configured to be called by cron (check in /etc/cron.daily if you have a script called logrotate there), but which can also be called manually (/usr/sbin/logrotate /etc/logrotate.conf).

WoJ
  • 27,165
  • 48
  • 180
  • 345
  • Meance, If I want it to detect file size by system and handle new log file. like , mysql error.log files-> If size of that file exceed then it create new one and old one get commpress. Is it possible in above line? – Pranay Jun 01 '15 at 11:23
  • @Pranay: if you look at the site I linked you will see that you can set many triggers for the files to be processed. You could for instance require that a file which is larger than 10 MB or older than 2 weeks will be renamed and compressed. – WoJ Jun 01 '15 at 11:28
  • sorry to asked, But How to use that Logrotate tag. It use directly or. include some code related. – Pranay Jun 01 '15 at 11:33
  • So, that meance, I can use It direct. 18,36,54 * * * * /usr/bin/perl /home/folder.my_perl.pl >> /usr/sbin/logrotate /etc/logrotate.conf/out.log 2>> /usr/sbin/logrotate /etc/logrotate.conf/error.log – Pranay Jun 01 '15 at 12:13
  • No, `logrotate` isn't something you write to: it is something that will independently rotate files on the file system. Since your program runs 3 times an hour, I assume it doesn't run continuously and thus you can use `logrotate` to rotate files daily outside of your program. Do `man logrotate` to see more details on how to configure it. – kjpires Jun 01 '15 at 12:34
  • Also, if you have a `/etc/logrotate.d` directory, check out some of the files in there and make one for your files. – kjpires Jun 01 '15 at 12:35
0

What you are doing is just opening file descriptors 1 and 2 to these files before the program is launched. It has no idea of where the output is going and so there's nothing it can do about managing it's output when called this way.

You could:

  1. have the program open the files and manage their size,
  2. have the output piped to another small script that manages the size independently,
  3. use Sys::Syslog,
  4. use Log::Dispatch::FileRotate,
  5. or any number of other logging modules.
kjpires
  • 730
  • 4
  • 14
  • If I used Sys Sys::Syslog and Log::Dispatch::FileRotate then, How it will help me here?Sorry but, I am using it first time so. – Pranay Jun 01 '15 at 11:42
  • `Sys::Syslog` is a system logger and it's log files are already rotated by `logrotate` (on Linux). `Log::Dispatch::FileRotate` is a library that logs data and automatically rotates the files which I thought is exactly what you want. Please read the `perldoc` on these modules for more details. (FYI: I've implemented Option 2 often when I wrap non-Perl programs and want them to syslog their stdout/stderr without modifying those programs, but each line comes with a timestamp.) – kjpires Jun 01 '15 at 14:59