Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Working with folders in Perl and HTML

by LinuxNoob (Initiate)
on May 29, 2017 at 00:03 UTC ( [id://1191462]=perlquestion: print w/replies, xml ) Need Help??

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

Hello Gys, I feel so noob when it comes to Linux/Unix world as I'm an MS nerd (bad career choice)... I have NEVER scripted anything on Linux before but today I'm in an uncomfortable situation where I have to learn and develop a web interface in Perl that will just go get the size and the creation date/time a set of folders on a Windows Server (2012 r2)... This seems to be quiet simple for a Perl programmer but it's a complete trouble for a person like me... Can any one of you guys help me out with this? as I'm sure that this won't take a few minutes to be set up for people like you.

Replies are listed 'Best First'.
Re: Working with folders in Perl and HTML
by hippo (Bishop) on May 29, 2017 at 08:11 UTC
    I have to learn and develop a web interface in Perl that will just go get the size and the creation date/time a set of folders on a Windows Server (2012 r2)

    Have you read perlintro? Start there, because without the basics you are going to sink very fast.

    Your task is actually 3 tasks:

    1. Connect (by some as yet unspecified protocol) to an alien (Win32) server
    2. Retrieve various FS data from the alien server
    3. Put a web interface on it

    Do these one at a time - ideally in the order above. Consider using Modules for separation of tasks. And always, always use strict and warnings.

    Good luck, especially with the Windows bit. That will probably be the tricky part.

      Thanks Hippo, I appreciate your help, I will base my research on you guide lines, you made it very easy for me, but I might be soliciting your help later on the coding part.
Re: Working with folders in Perl and HTML
by Marshall (Canon) on May 29, 2017 at 00:35 UTC
    Wow. First: "get the size and the creation date/time a set of folders on a Windows Server (2012 r2)..."

    The general idea of this is easy...But...you are using terminology that is confusing. The Unix file system doesn't have an idea of "file creation time", the idea of a "born on" date. The Windows NTFS system does have that "born on" idea. Perl can be used to access this specific Windows idea (with "extra work"), but usually that is not needed.

    Normally in Windows and in Unix, the stuff that matters are the: a) time since this file was modified, b) time since this file was last accessed for r/w. The Windows idea of when a file was originally created is seldom used, even with Windows programs.

    I don't understand your question. Can you give more details?
    Normally what is needed is: a) last time file was accessed, b) time the file was modified.

      Hey Marshall, The idea is just literally having a webpage on which you can see the size of a folder and its born on, nothing else. :)
        Hey, LinuxNoob,
        I think you will do fine with the standard Perl -M file test. If you are writing server code, I recommend code that works on both Unix and Windows. I would not assume that the target server is Windows - that could be and probably is a very bad assumption. I have written many Perl programs that work equally well on both Unix variants and Windows. See my reply to AnonMonk below re:"Born-on" time. This parameter is possible to get on Windows, but don't code that way unless you really need to do it and are aware of the incompatibility consequences.
      Born in date nevere used? Heh
        I said: "seldom used". Seldom does NOT mean never!

        Most applications do not need the Windows "born-on" date in order to work very well. Geez, all Unix applications seem to get along fine without it...

        This Windows file system parameter does have its uses. However, my recommendation would be to not use it unless necessary. That means only do it if, a) if the standard Perl multi-platform file tests do not provide adequate information and b)you are willing to write O/S specific code. In the OP's case, probably the -M file test is just fine. The "born-on" date requires a call to a Windows specific API.

Re: Working with folders in Perl and HTML
by Discipulus (Canon) on May 29, 2017 at 11:21 UTC
    Hello LinuxNoob and welcome to the monastery and to the wonderful world of Perl!

    well design, program and test a web interface it is not simple as you said: more, if i understand it correctly, if you want the webserver on Linux and retrieve folders statistics from a win2k12 remote server..

    If, by other hand, the webserver is on the windows machine itself, this can be easier.

    First install StrawberryPerl on the machine. Now you can use cpan client to install modules as in linux, because strawberry perl comes with a running compiler and many other goodies.

    Then you need to learn how to serve html pages: there are many different possibilities and among them Apache for windows. Apache has it's learning curve but is affordable.

    Then you have to write your web application: there are a zillion of possibilities of doing this using Perl: you can search and install (via cpan client) Dancer2 as easy way to start with. Another learning curve.

    If security is not an issue (well it is always an issue, but let's say you are in a protected env with strong firewall rules etc..) and you need some quick and dirty solution you can resolve with 2 lines of Perl (using UnxUtils to have du usable and Plack via cpan to have plackup at your disposal):

    # spaces added for readability # use a perl oneliner to have a minimal output redirected to an index. +html file # it print the folder name, the output of du -csh and mtime a nd ctime + from perl's stat builtin, finally a horizontal rule tag perl -lE "print $_.' '.`du -csh $_`,join' ',map{scalar localtime($_)}( +stat ($_))[9..10].'<hr>' for @ARGV" c:\scripts\chart c:\SCRIPTS\csidl > index.html # use plackup to start a webserver listening on port 5000 plackup -p 5000 -MPlack::App::Directory -e "Plack::App::Directory->new +({root => q{.}})->to_app" # point your browser at the index start http://localhost:5000/index.html # enjoy the result! c:\scripts\chart 35K c:\scripts\chart 35K total Thu Apr 19 14:06 +:24 2012 Tue Apr 10 17:31:54 2012 ---------------------------------------------------------------------- +--------------------------------- c:\SCRIPTS\csidl 16K c:\SCRIPTS\csidl 16K total Thu Apr 19 14:06 +:24 2012 Tue Apr 10 17:31:55 2012 ---------------------------------------------------------------------- +---------------------------------

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      You are using (stat)[10] to get the ctime which I didn't think would work on Win32 systems. It says in the documentation for stat:

      (*) Not all fields are supported on all filesystem types. Notably, the ctime field is non-portable. In particular, you cannot expect it to be a "creation time"; see Files and Filesystems in perlport for details.

      In perlport it states:

      ctime is creation time instead of inode change time (Win32).

      Thanks for posting.

      Hello Discipulus, Sorry for the delay, your method seems to be very helpful, I'm gonna try to use it and will let you know about the result. Thanks much!
Re: Working with folders in Perl and HTML
by Corion (Patriarch) on May 29, 2017 at 09:16 UTC

    If you have Perl running on the Windows 2012 machine, this job is mostly similar to doing the same on Linux.

    See readdir or glob for reading the directory, stat for reading the information on the entries.

    For output, a templating system like HTML::Template is likely the best, but for a start you can also do with printing the HTML directly.

Re: Working with folders in Perl and HTML
by stevieb (Canon) on May 29, 2017 at 01:28 UTC

    This:

    This seems to be quiet -sic- simple for a Perl programmer but it's a complete trouble for a person like me... Can any one of you guys help me out with this? as I'm sure that this won't take a few minutes to be set up for people like you.

    ...sounds like it is something your work is telling you to do.

    What people do in the real world is charge real-world finance for doing someone's job for them. Just because it is easy for people, doesn't mean that we're going to do your work for you, for nothing. If your job won't pay to get something like this done, why should anyone else while you get all the credit?

    This isn't a free code writing service here. You should let your employer know that they need to get some priorities straight.

      1st I'm not trying to hide why I'm asking for help on this topic so that you come out with such statement... 2nd I'm not asking for someone doing my job, all what've asked for is "help", some instructions, guide lines or a function/App to use... Thanks for you appreciable help.

        Hello, LinuxNoob. Welcome to the Monastery.

        I can appreciate that you didn't intend to ask for someone to do your job for you, but the way you phrased your opening post, that's sure what it looked like, hence the response above you received.

        But relax; nobody's attacking here, just making sure the path is clear and setting expectations.

        This is the Monastery; breathe.

        Once you're into the chill vibe about the place, you might find Perlmonks is a great place to visit even when you don't have a Perl problem.

        As to the technical answer -- other Monks have already chipped in with some useful direction for you; I will leave you to those.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1191462]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-03-28 13:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found