Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

run the find command in perl script from window server

by rrrrr (Novice)
on Oct 15, 2012 at 04:16 UTC ( #999006=perlquestion: print w/ replies, xml ) Need Help??
rrrrr has asked for the wisdom of the Perl Monks concerning the following question:

. How to run the unix find command from window server using perl script. below is my command.

#!/usr/bin/perl use warnings; use strict; my $wkDir; $wkDir ="/D/ARCHIVE/BIOS/PRTFILES"; system("find . -mtime +20 -type d \"${wkDir}\" -exec rm -rf {} \\;");
Since window has sep syntax its nt recognising my unix command. Kindly help me.

Comment on run the find command in perl script from window server
Download Code
Re: run the find command in perl script from window server
by thomas895 (Hermit) on Oct 15, 2012 at 05:11 UTC

    That won't work, at least, not in the way you have it now. To run a command on one machine from another, you must use something like SSH or Telnet.
    But if I'm understanding your intention correctly, you want to search your Windows flesystem using a Unix machine. Unfortunately, it's not that simple, unless you have already mounted your Windows drive using Samba(or something like that).

    Instead, consider using File::Find, and then unlinking the file you want to remove.

    HTH

    ~Thomas~
    confess( "I offer no guarantees on my code." );
Re: run the find command in perl script from window server
by kcott (Abbot) on Oct 15, 2012 at 05:12 UTC

    G'day rrrrr,

    You posted exactly the same code four days ago (File not found error) and it was pointed out to you that the syntax was wrong. Why are you expected it to work on any OS?

    File::Find should work in either OS. See -X to check for directories and modification times.

    -- Ken

Re: run the find command in perl script from window server
by blue_cowdawg (Prior) on Oct 15, 2012 at 17:22 UTC
        How to run the unix find command from window server using perl script. below is my command.

    If you have cygwin installed on windows server (not sure about Strawberry Perl or friends) you can run find2perl to create a Perl script for you and then tailor that script for your needs.

    Example:

    $ find2perl /var -name '*.log' -mtime +7 -print #! /usr/bin/perl -w eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0; #$running_under_some_shell use strict; use File::Find (); # Set the variable $File::Find::dont_use_nlink if you're using AFS, # since AFS cheats. # for the convenience of &wanted calls, including -eval statements: use vars qw/*name *dir *prune/; *name = *File::Find::name; *dir = *File::Find::dir; *prune = *File::Find::prune; sub wanted; # Traverse desired filesystems File::Find::find({wanted => \&wanted}, '/var'); exit; sub wanted { my ($dev,$ino,$mode,$nlink,$uid,$gid); /^.*\.log\z/s && (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && (int(-M _) > 7) && print("$name\n"); }
    Where you see the call  print("$name\n""); you can substitute anything your heart desires and get the functionality you really want.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: run the find command in perl script from window server
by aitap (Deacon) on Oct 15, 2012 at 17:36 UTC

    There is no UNIX find on Windows by default (Windows' find acts like UNIX grep), but you may install one from GnuWin32, MSYS, Cygwin or somewhere else.

    And it's a better idea to use File::Find instead, as pointed above.

    Sorry if my advice was wrong.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (18)
As of 2014-08-27 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (252 votes), past polls