Hello and welcome to the Webmasters Forums!. This is the best place to get webmasters resources for free. Get $2 for free today, read more - Make your payment today. Download premium and professional templates for free. Get free web hosting without ads, read more. You can get lot more by simply join with this forum. To gain full access to the forums you must sign up for a free account.


Post Reply  Post Thread 

Pipe I/O and System Calls

Post Bank
Posting Manager
******

Posts: 995
Group: Forum Team
Joined: Sep 2006
Status: Online
Make money from now. You can make money just for posting on this forum. Every discussions on this community gives you more money. $2 minimum payout. So get your payment today, SignIn with this forum.

Signin to Remove this Post

bomber
Junior Member
*


Posts: 34
Group: Registered
Joined: Sep 2006
Status: Offline
Reputation: 0
Points: 250 (Donate)
Post: #1

Smile Pipe I/O and System Calls


Code:
#!/usr/local/bin/perl
    # Report on disk usage under specified files
    # The Unix command "du -sk ..." (on BSD Unix, "du -s ...")
    # produces a series of lines:
    #   1942    bin
    #   2981    etc
    #   ...
    # listing the K bytes used under each file or directory.
    # It doesn't show other information, such as the
    # modification date or owner.
    # This program gets du's kbytes and filename, and merges
    # this info with other useful information for each file.
    #

    $files = join(' ',@ARGV);

    # The trailing pipe "|" directs command output
    # into our program:

    if (! open (DUPIPE,"du -sk $files | sort -nr |"))  {
        die "Can't run du! $!\n";
    }

    printf "%8s %-8s %-16s %8s %s\n",
        'K-bytes','Login','Name','Modified','File';
    while (<DUPIPE>) {
        # parse the du info:
        ($kbytes, $filename) = split;

        # Call system to look up file info like "ls" does:
        ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,
            $size,$atime,$mtime,$ctime)
            = stat($filename);

        # Call system to associate login & name with uid:
        if ($uid != $previous_uid) {
            ($login,$passwd,$uid,$gid,$quota,$comment,
                $realname,$dir,$shell) = getpwuid($uid);
            ($realname) = split(',',substr($realname,0,20));
            $previous_uid = $uid;
        }

        # Convert the modification-time to readable form:
        ($sec,$min,$hour,$mday,$mon,$myear) = localtime($mtime);
        $mmonth = $mon+1;

        printf "%8s %-8s %-16s %02s-%02d-%02d %s\n",
            $kbytes, $login, $realname,
            $myear, $mmonth, $mday, $filename;
    }


Demonstration Output

Quote:
K-bytes Login Name Modified File
40788 c527100 Fred Flintstone 95-10-05 c527100
32685 c565060 Peter Parker 95-10-05 c565060
24932 c579818 Clark Kent 95-10-06 c579818
15388 c576657 Lois Lane 95-10-06 c576657
9462 c572038 Bruce Wayne 95-10-06 c572038
8381 c517401 Eric McGregor 95-10-05 c517401
7022 c594912 Asterisk de Gaul 95-10-05 c594912

19-09-2006 12:34 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites
Rate This Thread:

Forum Jump:

Sign In to Remove Ads

Download 1000's of web templates. Unlimited access!
World's Best Web Hosting
Website of the Month

Create-a-Page for Free
SOTM June 2008


Accepting Submissions
for July 2008
Resources

Recommended Sites:



Visit our Sponsors!

Current time: 20-08-2008, 05:37 PM


Copyright © 2002-2008 MyBB Group
Powered By MyBB