Perl questions - more


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl questions - more
# 1  
Old 10-02-2007
Perl questions - more

More questions for Perl on Windows (again I apologize its on windows... )

1. How can I check free disk space on a drive in windows using perl command in a script?

2. How can I check processes running using perl command (as I would normally be able to see in task manager for example)

3. I need to check to see if particular files exist in a directory within the last 1 hour or last 2 hours... How can I do this in perl?


Again - I dont have a lot of experience in perl so any specific examples you can give me would be much appreciated Smilie
# 2  
Old 10-03-2007
My impression is that most of the requirements you mentioned suggest some plausible use cases for Windows Script Host (WSH), which gives scripting access to a subset of the Windows API via a scripting environment. ActivePerl on Windows has an extension to support WSH if all you want to access are Windows-specific facilities. I do not have much exposure to this kind of scripting so I cannot give you any concrete code here.

I would suggest you look at ActivePerl's interface to WSH at
ActivePerl 5.8 - Online Docs : Windows Script Host

and MSDN's scripting reference Scripting

for further information. A quick browse I see the Scripting.FileSystemObject that supports a "freespace" attribute, a "dateCreated" property for files. I can't find process management in this glance but probably I just overlooked it.
# 3  
Old 10-03-2007
Afraid I cannot figure our the code that I would need to use with wsh - I have no objections to using it (assuming I dont have to install anything else)


Can anyone help?

Examples of code to help me out would be great if possible..
# 4  
Old 10-03-2007
I assume you can use vbscript besides perl.

Quote:
Originally Posted by frustrated1
1. How can I check free disk space on a drive in windows using perl command in a script?
Code:
Const HARD_DISK = 3
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")
For Each objDisk in colDisks
    Wscript.Echo "DeviceID: "& vbTab &  objDisk.DeviceID       
    Wscript.Echo "Free Disk Space: "& vbTab & objDisk.FreeSpace
Next

usage: save as checkDiskSpace.vbs then on command line, type:
Code:
c:\> cscript checkDiskSpace.vbs

Quote:
2. How can I check processes running using perl command (as I would normally be able to see in task manager for example)
Code:
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")
For Each objProc in colProcesses
    Wscript.Echo "Caption: "& vbTab &  objProc.Caption    
    Wscript.Echo "Command Line: "& vbTab & objProc.CommandLine
Next

usage: save as checkProcess.vbs and type
Code:
c:\> cscript checkProcess.vbs

Quote:
3. I need to check to see if particular files exist in a directory within the last 1 hour or last 2 hours... How can I do this in perl?
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
myFileToCheck = "c:\test\test.txt"
If objFSO.FileExists(myFileToCheck) Then
	WScript.Echo "file exists"
Else
	WScript.Echo "file does not exist"
End If

# 5  
Old 10-03-2007
Thanks - this helps..


1. Instead of echo the output to terminal can I output it to a file? If so how.
I am sure this is simple but I dont know vbs...

2. Can I run the cscript itsself using a perl call?
ie I have a perl script checking a few other things - can I get the perl script to execute the vbs script ?
# 6  
Old 10-03-2007
Quote:
Originally Posted by frustrated1
Thanks - this helps..


1. Instead of echo the output to terminal can I output it to a file? If so how.
I am sure this is simple but I dont know vbs...
use the redirection operator ! > or >>

Quote:
2. Can I run the cscript itsself using a perl call?
ie I have a perl script checking a few other things - can I get the perl script to execute the vbs script ?
you can use system().? or other methods in perl that can call external commands.
try this: perldoc -q external
# 7  
Old 10-08-2007
Back again - thanks for all your help to date - really getting me through what I need...


I need to know how to check if the modified time of a directory is within the last 1 or 2 hours using either vbs or perl script..

How can I do this?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

2. Shell Programming and Scripting

Perl Debug Stepping Answering Questions

I am new to perl and want to get a little better understanding of debugging code in perl. I have a perl script that has questions to be answered like: he following PERL modules are recommended: Crypt::DES Crypt::PasswdMD5 IO::Pty Net::Write::Layer2 String::CRC32 Attempt to install... (0 Replies)
Discussion started by: metallica1973
0 Replies

3. Homework & Coursework Questions

Print questions from a questions folder in a sequential order

1.) I am to write scripts that will be phasetest folder in the home directory. 2.) The folder should have a set-up,phase and display files I have written a small script which i used to check for the existing users and their password. What I need help with: I have a set of questions in a... (19 Replies)
Discussion started by: moraks007
19 Replies

4. Shell Programming and Scripting

Perl newbie questions!

Hi, So I started to learn perl a few days ago, and I have some problems... One of my problems... #!C:\Perl64\bin\perl.exe -w use LWP::Simple; print "Content-Type: Text/Plain\n\n"; sub pagelinks { return @all = get($_) =~ /href\s*=\s*"?(+)/gis; } @a =... (5 Replies)
Discussion started by: byte1918
5 Replies

5. Shell Programming and Scripting

How to answer the Questions in Perl .

I need to write a script to telnet or ssh a device the execute some commands in device then copy the output in a file, I wrote the script but I faced one issue, when you execute some commands the device asked me a Question, for example : device # copy run tftp device # Source filename ? ... (3 Replies)
Discussion started by: DarkSoul
3 Replies

6. Shell Programming and Scripting

perl questions

New to perl and a few questions - usually used to shell scripting but have to write a script to check a few things on windows server and need help.. 1. Check for file missing in sequence.. ie. list of file in directory as follows: file0001.txt file0002.txt file0004.txt file0005.txt... (7 Replies)
Discussion started by: frustrated1
7 Replies

7. Shell Programming and Scripting

chess perl program questions

Hello guys, While going over the book, I ran into this chess program and I have few questions 1) on line 40), why is not $chessboard-> ) ??? 40 unless (defined $chessboard->) { 2) 20 foreach my $i (reverse (0..7)) { #Row 1 #!/usr/bin/perl -w 2 # 3 # 4 5 ... (1 Reply)
Discussion started by: hankooknara
1 Replies

8. Shell Programming and Scripting

Perl: answering automatically to install questions

Hi everybody, I have been looking for an answer to this issue both on google and on the forum, but I couldn't find anything. please help me :eek: As part of an automated (in perl) install of Solaris 9, I would like to be able to answer automaticaly to the question the installer asks.... (2 Replies)
Discussion started by: zaap
2 Replies

9. Shell Programming and Scripting

bash and Perl interaction questions

hi. i´m working in bash and am trying to create a Perl daemon that controls bash´s behavior. this is actually in preparation for a later project i´ll be working on. basically, i´m looking for a way to have the Perl daemon tell bash what to do. i already have a small daemon that simply prints... (2 Replies)
Discussion started by: deryk
2 Replies
Login or Register to Ask a Question