in reply to Re: SEQUENTIAL REBOOT ORDER WINDOW$
in thread SEQUENTIAL REBOOT ORDER WINDOW$

That worked, now I just need to grep "invalid" within $_ and kill the perl script if it encounters an error with the reboots. When I redo the code, I'll post it here, but you definitely helped move me in the right direction. Thanks.
- 3dbc

Replies are listed 'Best First'.
Re^3: SEQUENTIAL REBOOT ORDER WINDOW$
by 3dbc (Monk) on Feb 07, 2018 at 21:28 UTC
    updated the foreach section, you might have to move around some of the comments because I was experimenting with other commands like ipconfig to see if I can parse the output of a remote machine, which i can ;-) thankfully due to this post kicking my ass in the right direction!:
    sub getDOS { print "This is dollar 0 $_[0]\n\n"; open TASK, "$_[0] 2>&1|" or die "cannot open pipe to DOS"; my @return; while (<TASK>) { #chomp; #chop; #print; #return $_; push @return, $_; } return @return; } foreach (@servers){ my $externalExe = qq(psexec.exe \\\\$_ -u ); $externalExe .= $dev_cred . " -p "; #$externalExe .= $prod_pass . ' -i -d cmd /c shutdown /r /f /t 0'; $externalExe .= $dev_pass . ' ipconfig'; print "\n\n... Program START: \n\n $externalExe \n \n"; my @output = getDOS($externalExe); print "\n\nReturned output from DOS command:\n"; foreach(@output){ print; die if $_ =~ /$[Ee]rror/; die if $_ =~ /[Ii]nvalid/; } #wmic process call create "cmd /C > C:\temp\test.txt 2>&1 netstat. +exe -ano" #PsExec v2.2 - Execute processes remotely #Copyright (C) 2001-2016 Mark Russinovich #Sysinternals - www.sysinternals.com #The handle is invalid. #Error communicating with PsExec service on PR0235IPRT002: #print for qx|$externalExe 2>&1|; # Executes the program, and prin +ts it's output print "\n\n.... run complete ...\n"; sleep 360; }


    next goal is to make this asynchronous and get rid of the sleep command in the loop. I'm going to build in pings / and more psexec's where I parse the output to ensure the server is up before moving onto the next. Also going to include some net server stop commands to more gracefully stop some of the services before doing a forced shutdown.
    - 3dbc
      I know I'm virtually writing to myself, but still able to get a few votes so hopefully some win32 monks are following along, otherwise I'll spawn a new thread. Starting to notice that my psexec approach to run a forced shutdown isn't always going through, because when I run a
      wmic os get lastbootuptime
      doesn't list the current date / time even after successfully triggering a psexec forced reboot over 6 min prior to checking. ie.:
      psexec.exe \\host-u domain\japh -p obfuscate -i -d cmd /c shutdown /r +/f /t 0
      Returns:
      PsExec v2.2 - Execute processes remotely Copyright (C) 2001-2016 Mark Russinovich Sysinternals - www.sysinternals.com Starting cmd on perlhost...n perlhost... cmd started on perlhost with process ID 9088.
      but perhaps my psexec syntax is off or else I should be using another method to remotely force shutdown of windows servers.
      - 3dbc