RayRay459 has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks, I created individual scripts that do their job and work, so i thought that i might write one big script and call upon the little ones as subRoutines.
The script is prompting for a text file to read in of machine names and a password to assign to a local account on the machines. I am encryping the password in a text file and copying that over. I am also compiling a perl script to an exe and copying that too and executing it.
Here are both, the final script and the code of the exe. I will list the errors i am getting at the end. If anyone can help me figure out why i am getting these errors and how to remedy them, i would greatly appreciate it.
Thanks in advance.
Ray
# Ray Espinoza # ChAdminPass.pl # This is the completed script that will change the local admin passwo +rd on a list of machines # that you specify. It will ask for a password, encrypt it and copy ov +er with a compiled exe of this # perl script. The script will then be decrypted locally on the machin +e and change the password and # delete the encryted text file along with the executable. ###################################################################### +############################### #!D:\perl\bin use strict; use Crypt::Blowfish_PP; use Win32::AdminMisc; ###################################################################### +######################### # This will prompt user for the list of machines to read in and the pa +ssword to assign ###################################################################### +######################### print "Enter in the name of the text file that you would like to read +in:\n"; chomp(my $List = <STDIN>); print "Enter in the password that you would like to assign the local a +dmin account:\n"; chomp(my $Password = <STDIN>); ###################################################################### +########################## # Calling on subRoutine to Encrypt the password and adding it to text +file. ###################################################################### +########################## Create_Password(); ###################################################################### +########################## # This will open the list file for reading or error if it can't find i +t. ###################################################################### +########################## open(LIST,$List) || die "Can't read $List: $!"; ###################################################################### +########################## # This will read in the text file line by line and execute the copy of + files over to the local # machine and execute ChPass.exe ###################################################################### +########################## while (<LIST>) { my $Server = $_; my $source1 = "C:/ChPass/phrase.txt"; my $dest1 = "//$Server/c\$/temp/phrase.txt"; my $command = qq(copy "$source1" "$dest1") || die "Couldn't copy $source1: $!"; $command =~ s#/#\\#g; system $command; my $source2 = "C:/ChPass/ChPass.exe"; my $dest2 = "//$Server/c\$/temp/ChPass.exe"; my $command2 = qq(copy "$source2" "$dest2") || die "Couldn't copy $source2: $!"; $command2 =~ s#/#\\#g; system $command2; system("//$Server/c\$/temp/ChPass.exe $Server); } ###################################################################### +########################### # This is the subroutine that encrypts the password. ###################################################################### +########################### sub Create_Password { open(OUT,">phrase.txt") #|| die "Can't create phrase.txt: $!"; my $key = "abcdefghijklmnopqrstuvwxyz123456789"; my $bf = Crypt::Blowfish_PP->new($key); print my $encrypted_Password = $bf->encrypt($Password); print OUT $encrypted_Password; } ###################################################################### +########################## # Closes any open files gracefully. ###################################################################### +########################## close(OUT); close(LIST); # Here is the next script (ChPass.pl before it is ChPass.exe) # Ray Espinoza # ChPass.pl # This script calls in the encrypted password file and decrypts it and + uses # its value as $Password to change the account password to $Password. ###################################################################### +########################### #!D:\perl\bin -w use strict; use Win32::AdminMisc; #use Win32::AdminMisc qw(SetPassword); chomp(my $Server = <STDIN>); my $User = "Administrator"; my $Password = &getPassword; my $Result = Win32::AdminMisc::SetPassword( $Server, $User, $Password) + || die "Couldn't change password on $Server: $^E"; print $Password . "\n"; print $Result; sub getPassword { use Crypt::Blowfish_PP; my $key="abcdefghijklmnopqrstuvwxyz123456789"; my $bf = Crypt::Blowfish_PP->new($key); open (IN,"phrase.txt") || die "Can't read phrase.txt: $!"; my $encrypted_password = <IN>; my $decrypted_password = $bf->decrypt($encrypted_password); return $decrypted_password; close(IN); } # Here are the errors that i am getting: String found where operator expected at C:\scripts\perl\ChAdminPass.pl + line 65, near "txt") #|| die "" Bareword found where operator expected at C:\scripts\perl\ChAdminPass. +pl line 65 , near "") #|| die "Can't" (Missing operator before Can't?) String found where operator expected at C:\scripts\perl\ChAdminPass.pl + line 67, near "$key = "" (Might be a runaway multi-line "" string starting on line 65) (Missing semicolon on previous line?) Bareword found where operator expected at C:\scripts\perl\ChAdminPass. +pl line 67 , near "$key = "abcdefghijklmnopqrstuvwxyz123456789" (Missing operator before abcdefghijklmnopqrstuvwxyz123456789?) String found where operator expected at C:\scripts\perl\ChAdminPass.pl + line 67, at end of line (Missing semicolon on previous line?) syntax error at C:\scripts\perl\ChAdminPass.pl line 65, near "txt") #| +| die "" Global symbol "$key" requires explicit package name at C:\scripts\perl +\ChAdminPa ss.pl line 65. Can't find string terminator '"' anywhere before EOF at C:\scripts\per +l\ChAdminP ass.pl line 67.

Replies are listed 'Best First'.
Re: Problems with my (almost) finished product
by rchiav (Deacon) on Aug 23, 2001 at 04:04 UTC
    I think this is line 65..
    open(OUT,">phrase.txt") #|| die "Can't create phrase.txt: $!";
    Were you trying to comment the || out? If so, where's you EOL ";"?

    Above that, I see..

    system("//$Server/c\$/temp/ChPass.exe $Server);
    You're missing an ending quote. I'm guessing this is going to fix quite a bit of your errors.
    (Might be a runaway multi-line "" string starting on line 65)
    Is usually pretty accurate. You should check all your strings when you see this.

    Hope this helps..
    Rich

      A little addition, using a proper editor with syntax highlighting can easily catch the missing quotes errors (and quite a few others). I'd suggest taking a look our Code Editors in Outside Links.

      -- Hofmator

Re: Problems with my (almost) finished product
by jryan (Vicar) on Aug 23, 2001 at 04:14 UTC

    You had a few syntax errors in your Create Password sub. Here are the fixes:

    sub Create_Password { # it was trying to interpret #|| as a bareword... # also use or instead of || when dieing, its safer open(OUT,">phrase.txt") or die "Can't create phrase.txt: $!"; my $key = "abcdefghijklmnopqrstuvwxyz123456789"; my $bf = Crypt::Blowfish_PP->new($key); # you had "print my $encrypted password"... i assume this was a typo my $encrypted_Password = $bf->encrypt($Password); print OUT $encrypted_Password; }
      Don't assume. Test, and sometimes you will learn new tricks.

      It is perfectly legal to declare a variable with my as you are using it.