- 论坛徽章:
- 0
|
楼主你提问的能力真的很强大。
这是写文件的代码:- my $log_output = "config.log";
- unlink $log_output;
- open(FILE,">$log_output");
- while (1) {
- print "Enter your host ip:\n";
- $inputip = <STDIN>;
- chomp($inputip);
- exit if($inputip=~/\bexit\b/);
- print(FILE "$inputip\t\t");
- print "Enter your host username:\n";
- $inputusername = <STDIN>;
- chomp($inputusername);
- exit if($inputusername=~/\bexit\b/);
- print(FILE "$inputusername\t\t");
-
- system "stty -echo";
- print "Enter your host password:\n";
- $inputpasswd = <STDIN>;
- chomp($inputpasswd);
- exit if($inputpasswd=~/\bexit\b/);
- $encryppasswd = encode_base64($inputpasswd);
- system "stty echo";
- print(FILE $encryppasswd);
- }
- close(FILE);
复制代码 这是读文件的代码:- my ($hostlist) = @ARGV;
- my $HANDLE;
- print $hostlist;
- open (HANDLE, $hostlist) or die("ERROR: Can not locate \"$hostlist\" input file!\n");
- my @lines = <HANDLE>;
- my @errorArray;
- my $line_no = 0;
- close(HANDLE);
- foreach my $line (@lines) {
- $line_no++;
- &TrimSpaces($line);
- if($line) {
- if($line =~ /^\s*:\s*$/){
- print "Error in Parsing File at line: $line_no\n";
- print "Continuing to the next line\n";
- next;
- }
- (my $host, my $user, my $passwd) = split($line);
- &TrimSpaces($host);
- push @hostlist,$host;
- push @userlist,$host;
- push @passwdlist,$host;
- }
- }
复制代码 |
|