<p>Currently I monitoring a particular file with a simple shell one-liner:</p>

<pre><code>filesize=$(ls -lah somefile |  awk '{print $5}')
</code></pre>

<p>I'm aware that Perl has some nice modules to deal with Excel files so the idea is to, let's say, run that check daily, perhaps with cron, and write the result on a spreadsheet for further statistical use.</p>

[{'answer_id': 71668, 'author': 'Aristotle Pagaltzis', 'author_id': 9410, 'author_profile': 'https://Stackoverflow.com/users/9410', 'pm_score': 3, 'selected': False, 'text': '<p>You can use <a href="http://p3rl.org/-X" rel="nofollow noreferrer">the <code>-s</code> operator</a> to obtain the size of a file and the <a href="http://search.cpan.org/perldoc?Spreadsheet::ParseExcel" rel="nofollow noreferrer">Spreadsheet::ParseExcel</a> and <a href="http://search.cpan.org/perldoc?Spreadsheet::WriteExcel" rel="nofollow noreferrer">Spreadsheet::WriteExcel</a> modules to produce an updated spreadsheet with the information. <a href="http://search.cpan.org/perldoc?Spreadsheet::ParseExcel::SaveParser" rel="nofollow noreferrer">Spreadsheet::ParseExcel::SaveParser</a> lets you easily combine the two, in case you want to update an existing file with new information. If you are on Windows, you may want to automate Excel itself instead, probably with the aid of <a href="http://search.cpan.org/perldoc?Win32::OLE" rel="nofollow noreferrer">Win32::OLE</a>.</p>\n'}, {'answer_id': 71679, 'author': 'Leon Timmermans', 'author_id': 4727, 'author_profile': 'https://Stackoverflow.com/users/4727', 'pm_score': 2, 'selected': False, 'text': '<p>The module you should be using is <a href="http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel/lib/Spreadsheet/WriteExcel.pm" rel="nofollow noreferrer">Spreadsheet::WriteExcel</a>.</p>\n'}, {'answer_id': 71716, 'author': 'szabgab', 'author_id': 11827, 'author_profile': 'https://Stackoverflow.com/users/11827', 'pm_score': 4, 'selected': True, 'text': '<p>You can check the size of the file using the -s operator.</p>\n\n<pre>\nuse strict;\nuse warnings;\n\nuse File::Slurp qw(read_file write_file);\nuse Spreadsheet::ParseExcel;\nuse Spreadsheet::ParseExcel::SaveParser;\nuse Spreadsheet::WriteExcel;\n\nmy $file       = \'path_to_file\';\nmy $size_file  = \'path_to_file_keeping_the_size\';\nmy $excel_file = \'path_to_excel_file.xls\';\n\nmy $current_size = -s $file;\nmy $old_size = 0;\nif (-e $size_file) {\n   $old_size = read_file($size_file);\n}\n\nif ($old_size new;\n        my $excel = $parser->Parse($excel_file);\n        my $row = 1;\n        $row++ while $excel->{Worksheet}[0]->{Cells}[$row][0];\n        $excel->AddCell(0, $row, 0, scalar(localtime));\n        $excel->AddCell(0, $row, 1, $current_size);\n\n        my $workbook = $excel->SaveAs($excel_file);\n        $workbook->close;\n\n    } else {\n        my $workbook  = Spreadsheet::WriteExcel->new($excel_file);\n        my $worksheet = $workbook->add_worksheet();\n        $worksheet->write(0, 0, \'Date\');\n        $worksheet->write(0, 1, \'Size\');\n\n        $worksheet->write(1, 0, scalar(localtime));\n        $worksheet->write(1, 1, $current_size);\n        $workbook->close;\n    }\n}\n\nwrite_file($size_file, $current_size);\n</pre>\n\n<p>A simple way to write Excel files would be using\n<a href="http://search.cpan.org/dist/Spreadsheet-Write/" rel="noreferrer">Spreadsheet::Write</a>.\nbut if you need to update an existing Excel file you should look into\n<a href="http://search.cpan.org/dist/Spreadsheet-ParseExcel/" rel="noreferrer">Spreadsheet::ParseExcel</a>.</p>\n'}, {'answer_id': 72229, 'author': 'Michael Cramer', 'author_id': 1496728, 'author_profile': 'https://Stackoverflow.com/users/1496728', 'pm_score': 2, 'selected': False, 'text': '<p>You can also skip the hassle of writing .xls format files and use a more generic (but sufficiently Excel-friendly) format such as CSV:</p>\n\n<pre><code>#!/bin/bash\ndate=`date +%Y/%m/%d:%H:%M:%S`\nsize=$(ls -lah somefile |  awk \'{print $5}\')\necho "$date,$size"\n</code></pre>\n\n<p>Then, in your crontab:</p>\n\n<pre><code>0 0 * * * /path/to/script.sh &gt;/data/sizelog.csv\n</code></pre>\n\n<p>Then you import that .csv file into Excel just like any other spreadsheet.</p>\n'}, {'answer_id': 72868, 'author': 'Darren Meyer', 'author_id': 7826, 'author_profile': 'https://Stackoverflow.com/users/7826', 'pm_score': 2, 'selected': False, 'text': '<p>Perl also has the very nice (and very <em>fast</em>) <a href="http://search.cpan.org/search?query=text%3A%3Acsv_xs&amp;mode=module" rel="nofollow noreferrer">Text::CSV_XS</a> which allows you to easily make Excel-friendly CSV files, which may be a better solution than creating proper XLS files.</p>\n\n<p>For example (over-commented for instructional value):</p>\n\n<pre><code>#!/usr/bin/perl\npackage main;\nuse strict; use warnings; # always!\n\nuse Text::CSV_XS;\nuse IO::File;\n\n# set up the CSV file\nmy $csv = Text::CSV_XS-&gt;new( {eol=&gt;"\\r\\n"} );\nmy $io  = IO::File-&gt;new( \'report.csv\', \'&gt;\')\n  or die "Cannot create report.csv: $!\\n";\n\n# for each file specified on command line\nfor my $file (@ARGV) {\n    unless ( -f $file ) {\n        # file doesn\'t exist\n        warn "$file doesn\'t exist, skipping\\n";\n        next;\n    }\n\n    # get its size\n    my $size = -s $file;\n\n    # write the filename and size to a row in CSV\n    $csv-&gt;print( $io, [ $file, $size ] );\n}\n\n$io-&gt;close; # make sure CSV file is flushed and closed\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/71643', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6992/']