SSH Script to Control Router
HI, I'm able to SSH into the router successfully using putty.
But it's not working when I'm trying to automate the script using a bat files, ps1 files. I've even tried paramiko and netmiko with no avail.
Here's my script for instance
# Variables
$router_ip = "192.168.0.1"
$username = "admin"
$password = "password_goes_here"
$plink_path = "C:\Program Files\PuTTY\plink.exe" # Adjust this path as needed
# Read commands from the file
$commands = Get-Content -Path "commands.txt" -Raw
# Construct the plink command
$plink_command = "&'$plink_path' -ssh $username@$router_ip -pw $password -batch -m commands.txt"
# Execute the plink command and capture output and error
Write-Output "Executing plink command..."
$output = Invoke-Expression $plink_command 2>&1 | Out-String
# Display the output
Write-Output "Output:"
Write-Output $output
# Check if the VLAN creation was successful
if ($output -like "*VLAN creation and configuration completed*") {
Write-Output "VLAN created successfully"
} else {
Write-Output "VLAN creation failed. Please check the router configuration."
}
And the commands.txt is as follows:
enable
configure
vlan 11
name created_using_automated_SSH
exit
exit
Any idea how to go about it?
Many thanks!
- Copy Link
- Subscribe
- Bookmark
- Report Inappropriate Content
Hi @PiyushBQ
Thanks for posting in our business forum.
The CLI is limited. It is not working like the way you think in Openwrt or any sort of open-source routers.
The CLI you entered is a limited version that only supports the commands from the CLI User Guide.
We don't provide any sort of root access support or help. Or the way to enter it.
We do not offer any help to create the bat or automation. The "limited" CLI does not allow such a config or the script.
If you need to have the script support, please start a request thread on the correct page. We will record it accordingly.
- Copy Link
- Report Inappropriate Content
Hi @Clive_A
" The CLI you entered is a limited version that only supports the commands from the CLI User Guide. "
These commands are taken directly from the CLI user guide. The first screenshot shows the commands are working when done manually.
" If you need to have the script support, please start a request thread on the correct page. We will record it accordingly. "
What would be a "correct page" for this thread?
- Copy Link
- Report Inappropriate Content
Hi @PiyushBQ
Thanks for posting in our business forum.
The CLI is limited. It is not working like the way you think in Openwrt or any sort of open-source routers.
The CLI you entered is a limited version that only supports the commands from the CLI User Guide.
We don't provide any sort of root access support or help. Or the way to enter it.
We do not offer any help to create the bat or automation. The "limited" CLI does not allow such a config or the script.
If you need to have the script support, please start a request thread on the correct page. We will record it accordingly.
- Copy Link
- Report Inappropriate Content
Hi @Clive_A
" The CLI you entered is a limited version that only supports the commands from the CLI User Guide. "
These commands are taken directly from the CLI user guide. The first screenshot shows the commands are working when done manually.
" If you need to have the script support, please start a request thread on the correct page. We will record it accordingly. "
What would be a "correct page" for this thread?
- Copy Link
- Report Inappropriate Content
Hi @PiyushBQ
Thanks for posting in our business forum.
PiyushBQ wrote
Hi @Clive_A
" The CLI you entered is a limited version that only supports the commands from the CLI User Guide. "
These commands are taken directly from the CLI user guide. The first screenshot shows the commands are working when done manually.
" If you need to have the script support, please start a request thread on the correct page. We will record it accordingly. "
What would be a "correct page" for this thread?
Are you sure the commands in the script are supported?
I know the commands in below the scripts or the screenshots are the commands from the CLI guide but not the parameters from the script.
I know the system is based on the LINXU but this does not mean you can use them in the CLI mode. That's what I wrote earlier.
If you need more commands available or a script feature, you should start a thread on the request page.
- Copy Link
- Report Inappropriate Content
Information
Helpful: 0
Views: 318
Replies: 3
Voters 0
No one has voted for it yet.