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.

In reply to Problems with my (almost) finished product by RayRay459

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.