amit_m
amit_m

Reputation: 1

Automate SSH Reboot Command

i got two grandstream ip phones that once in a while losing the pbx registration, only solution i came by is rebooting them (surprise surprise)

my idea for the simplest way to do it is by using ssh reboot command i can manually log in with putty and run the reboot command

so here's the thing currently the script i wrote looks like this

Start-Process .\plink.exe -ArgumentList "[email protected] -pw xxxxx" "reboot"

after running the script it prompts plink window with the text "Using username "admin". Access granted. Press Return to begin session." and i have to press enter button (return) before i can procced with manually writing the reboot command

any idea how to automate this thing? would love to hear if you have any better ideas for automating phone rebooting

Upvotes: 0

Views: 82

Answers (1)

amit_m
amit_m

Reputation: 1

if anyone in need of this, this is what we came up with (it's working)

$plinkPath = ".\plink.exe"
$hostt = "[email protected]"
$password = "xxxx"
$command = "reboot`n"
$sendenter = "\n"

# Start plink process
$process = Start-Process -FilePath $plinkPath -ArgumentList "-pw", $password, $hostt -NoNewWindow -PassThru

# Wait for the connection to establish
Start-Sleep -Seconds 2

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
Start-Sleep -Seconds 2
[System.Windows.Forms.SendKeys]::SendWait("reboot")
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")

Upvotes: -1

Related Questions