SSH Script to Control Router

SSH Script to Control Router

SSH Script to Control Router
SSH Script to Control Router
2024-08-07 15:00:59 - last edited 2024-08-09 02:14:08
Tags: #SSH
Model: ER605 (TL-R605)  
Hardware Version: V2
Firmware Version: 2.2.5

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!

  0      
  0      
#1
Options
2 Accepted Solutions
Re:SSH Script to Control Router-Solution
2024-08-09 02:14:03 - last edited 2024-08-09 02:14:08

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.

Best Regards! If you are new to the forum, please read: Howto - A Guide to Use Forum Effectively. Read Before You Post. Look for a model? Search your model NOW Official and Beta firmware. NEW features! Subscribe for the latest update!Download Beta Here☚ ☛ ★ Configuration Guide ★ ☚ ☛ ★ Knowledge Base ★ ☚ ☛ ★ Troubleshooting Manual ★ ☚ ● Be kind and nice. ● Stay on the topic. ● Post details. ● Search first. Don't be a lazy asker. ● Please don't take it for granted. ● No email confidentiality should be violated. ● S/N, MAC, and your true public IP should be mosaiced.
Recommended Solution
  1  
  1  
#2
Options
Re:SSH Script to Control Router-Solution
2024-08-18 10:10:03 - last edited 2024-08-18 10:10:25

 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?

Recommended Solution
  0  
  0  
#3
Options
3 Reply
Re:SSH Script to Control Router-Solution
2024-08-09 02:14:03 - last edited 2024-08-09 02:14:08

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.

Best Regards! If you are new to the forum, please read: Howto - A Guide to Use Forum Effectively. Read Before You Post. Look for a model? Search your model NOW Official and Beta firmware. NEW features! Subscribe for the latest update!Download Beta Here☚ ☛ ★ Configuration Guide ★ ☚ ☛ ★ Knowledge Base ★ ☚ ☛ ★ Troubleshooting Manual ★ ☚ ● Be kind and nice. ● Stay on the topic. ● Post details. ● Search first. Don't be a lazy asker. ● Please don't take it for granted. ● No email confidentiality should be violated. ● S/N, MAC, and your true public IP should be mosaiced.
Recommended Solution
  1  
  1  
#2
Options
Re:SSH Script to Control Router-Solution
2024-08-18 10:10:03 - last edited 2024-08-18 10:10:25

 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?

Recommended Solution
  0  
  0  
#3
Options
Re:SSH Script to Control Router
2024-08-19 01:19:59

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.

Best Regards! If you are new to the forum, please read: Howto - A Guide to Use Forum Effectively. Read Before You Post. Look for a model? Search your model NOW Official and Beta firmware. NEW features! Subscribe for the latest update!Download Beta Here☚ ☛ ★ Configuration Guide ★ ☚ ☛ ★ Knowledge Base ★ ☚ ☛ ★ Troubleshooting Manual ★ ☚ ● Be kind and nice. ● Stay on the topic. ● Post details. ● Search first. Don't be a lazy asker. ● Please don't take it for granted. ● No email confidentiality should be violated. ● S/N, MAC, and your true public IP should be mosaiced.
  1  
  1  
#4
Options

Information

Helpful: 0

Views: 201

Replies: 3

Tags

SSH
Related Articles