Jump to content

Recommended Posts

Posted (edited)

I need to change user's passwords remotely for Linux devices. I was recommended using plink for achieving the same, but I am facing little issue while resetting the passwords.

Sharing the command using which I change password via cmd (working): 

echo 'y' | plink.exe admin@X.X.X.X -pw Old-password -no-antispoof "echo -e 'Old-password\nNew-password\nNew-password'|(passwd)" > passwdChange.log

When I integrated it with AutoIT, I embedded the above command in a batch file as below.

@echo off
echo 'y' | plink.exe %1@%2 -pw %3 -no-antispoof "echo -e '%3\n%4\n%4'|(passwd)" > passwdChange.log

When I try to execute the above batch file via AutoIT Run/ShellExecute command it doesn't work properly (doesn't change password).

$DOS = Run(@ComSpec & " /c "&@ScriptDir &"\chpasswd.bat "&$sUser&" "&$sIP&" "&$sOldPwd&" "&$pwd, "", @SW_SHOWMAXIMIZED, $STDERR_CHILD + $STDOUT_CHILD)

Where I am going & what changes I need to make in order for this to work

Thank you in advance.

Edited by Iraj
Posted
  On 7/24/2023 at 7:38 AM, Jos said:

First thing I always do when a Run @Comspec doesn't work is change the /c to /k so the cmd window stays open and I can see any errors.

 

Expand  

when i run from cmd, it will proceed to change the password, but when i compile & run with autoit, it doesn't. Is the line ($DOS = Run(@ComSpec & " ....) correct?

  • Developers
Posted (edited)
  On 7/24/2023 at 8:31 AM, Iraj said:

when i run from cmd, it will proceed to change the password, but when i compile & run with autoit, it doesn't. Is the line ($DOS = Run(@ComSpec & " ....) correct?

Expand  

It is fully clear to me what you are doing, so did you try what I suggested as that is not clear from your answer?

If so, what was shown in the CMD window that remained open?

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted
  On 7/24/2023 at 10:12 AM, Jos said:

It is fully clear to me what you are doing, so did you try what I suggested as that is not clear from your answer?

If so, what was shown in the CMD window that remained open?

Expand  

yes, I ran, it showed me a blank prompt.

  • Developers
Posted

When you run manually, do you include the full path as well? 

Maybe that needs to be quoted when the full path contains spaces?

While testing please get rid of the last parameter ($STDERR_CHILD + $STDOUT_CHILD) to ensure output is shown in the actual console and keep using the /k.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

taken from some other script to solve a similar task:

#include <AutoItConstants.au3>

$PlinkDir='"C:\Program Files\PuTTY"'
$PlinkExe='"C:\Program Files\PuTTY\plink.exe"'

$CmdLine=$PlinkExe & " root@your.host.fqdn"
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $CmdLine = ' & $CmdLine & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$pid=Run($Cmdline,@TempDir,@SW_SHOW,$STDERR_MERGED + $STDIN_CHILD)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $pid = ' & $pid & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
Sleep(4000)

$StrRead=""
while ProcessExists ($pid)
    $NxRead=StdoutRead($pid)
    if $NxRead <> "" Then
        $StrRead &=$NxRead
        ConsoleWrite($NxRead)
    EndIf
    ; analyze the STRING for interactive password change, if the right time has come, send your input. Finally EXIT, terminate your strings with @CRLF
    $Wait4String="password:"
    if StringRight($StrRead,StringLen($Wait4String)) = $Wait4String Then
    StdinWrite($pid,$Str2Send & @CRLF)
    ConsoleWrite("Written: """ & $Str2Send & """"  & @CRLF)
    EndIf
    Sleep(100)
WEnd

$NxRead=StdoutRead($pid)
$StrRead&=$NxRead
StdioClose($pid)

ConsoleWrite("------------------------" & @CRLF)
ConsoleWrite($StrRead & @CRLF)
ConsoleWrite("------------------------" & @CRLF)

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Posted
  On 7/25/2023 at 3:24 PM, rudi said:

taken from some other script to solve a similar task:

#include <AutoItConstants.au3>

$PlinkDir='"C:\Program Files\PuTTY"'
$PlinkExe='"C:\Program Files\PuTTY\plink.exe"'

$CmdLine=$PlinkExe & " root@your.host.fqdn"
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $CmdLine = ' & $CmdLine & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$pid=Run($Cmdline,@TempDir,@SW_SHOW,$STDERR_MERGED + $STDIN_CHILD)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $pid = ' & $pid & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
Sleep(4000)

$StrRead=""
while ProcessExists ($pid)
    $NxRead=StdoutRead($pid)
    if $NxRead <> "" Then
        $StrRead &=$NxRead
        ConsoleWrite($NxRead)
    EndIf
    ; analyze the STRING for interactive password change, if the right time has come, send your input. Finally EXIT, terminate your strings with @CRLF
    $Wait4String="password:"
    if StringRight($StrRead,StringLen($Wait4String)) = $Wait4String Then
    StdinWrite($pid,$Str2Send & @CRLF)
    ConsoleWrite("Written: """ & $Str2Send & """"  & @CRLF)
    EndIf
    Sleep(100)
WEnd

$NxRead=StdoutRead($pid)
$StrRead&=$NxRead
StdioClose($pid)

ConsoleWrite("------------------------" & @CRLF)
ConsoleWrite($StrRead & @CRLF)
ConsoleWrite("------------------------" & @CRLF)

 

Expand  

Sorry, I may be wrong, but can you explain how to run this? I ran it & it doesn't take the password I have provided on the right output screen. 

 

Capture.PNG

  • 2 weeks later...
Posted

Hi,

haven't been available for a while: Did you set the content of the variable $Str2Send to hold your password?

$Str2Send="YourTopSecretPwd" & @crlf

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...