Newbie question - system command & arrays 
Author Message
 Newbie question - system command & arrays

greetings,
i'm trying to accomplish the following: i want to check the current
time on all my servers. the server names are currently in a text file
(one on each line). i would like to read the file in as an array and
issue the "net time \\servername" command on each line in the array.
each line of output should be written to a file.

this is what i have so far:

   open (DC, "c:/servers.txt") or die "Can't open servers.txt: $!";
   open (DCTIME, ">c:/serverime.txt")or die "Can't open
servertime.txt: $!";



i keep getting an error message when executing the last line
("system...").

please help!
thanks,

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 Newbie question - system command & arrays

Quote:
> [...] "net time \\servername" [..]

> open (DC, "c:/servers.txt") or die "Can't open servers.txt: $!";
> open (DCTIME, ">c:/serverime.txt")or die "Can't open servertime.txt:

$!";

Shouldn't it be ">c:/serverTime.txt" ?
Next time please copy-paste your original code. Thanks.

No it is :

        system("net time \\\\$_");

Quote:
};

But do you REALLY need to read from the array?
If not, you had better directly do :
while (<DC>) {
        system("net time \\\\$_");

Quote:
};
> please help!
> thanks,

np

Surely not!

If you're posting on this newsgroup then you are supposed to read the
responses here! No to mention that other people may be experiencing the
same problem as yours.

Makau.

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 Newbie question - system command & arrays
i currently have the following code:

open (SERVER, "c:/server.txt") or die "Can't open server.txt: $!";
open (SERVERTIME, ">c:/servertime.txt")  or die "Can't open
servertime.txt: $!";


        system("net time \\\\$_");
        };

i'm trying to print the output of the 'net time' command to the file
c:\servertime. however, the result of the net time command is printed
to the screen and the contents of c:\servertime.txt is the original
contents of c:\server.txt. what can i do to resolve this?

thanks,



Quote:

> > [...] "net time \\servername" [..]

> > open (DC, "c:/servers.txt") or die "Can't open servers.txt: $!";
> > open (DCTIME, ">c:/serverime.txt")or die "Can't open servertime.txt:
> $!";

> Shouldn't it be ">c:/serverTime.txt" ?
> Next time please copy-paste your original code. Thanks.



> No it is :

>         system("net time \\\\$_");
> };

> But do you REALLY need to read from the array?
> If not, you had better directly do :
> while (<DC>) {
>         system("net time \\\\$_");
> };

> > please help!
> > thanks,

> np


> Surely not!

> If you're posting on this newsgroup then you are supposed to read the
> responses here! No to mention that other people may be experiencing
the
> same problem as yours.

> Makau.

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.


Wed, 18 Jun 1902 08:00:00 GMT  
 Newbie question - system command & arrays

Quote:

> i currently have the following code:

<snip>

Quote:

>    system("net time \\\\$_");

perldoc -f system

"The return value is the exit status of the program as
returned by the C<wait()> call.  To get the actual exit value divide by
256.  See also L</exec>.  This is I<NOT> what you want to use to capture
the output from a command, for that you should use merely backticks or
C<qx//>, as described in L<perlop/"`STRING`">."

Quote:
>    };


your print probably needs to be inside the loop.  This print will only
print to SERVERTIME what was placed into the array by the read.

--

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Newbie question regarding system command

2. Newbie Question: CGI, Perl & UNIX system calls

3. Newbie: Arrays & Comparing Arrays

4. newbie - messy output from system command?

5. redirect system command to an array

6. Piping array contents to a system command

7. Newbie Q: perl & NT print command

8. Perl newbie question - arrays of arrays

9. HELP - question about system(LIST) command

10. Question about adduser command under linux use perl system function

11. System Command Question

12. system command syntax question

 

 
Powered by phpBB® Forum Software