3

I looked around and couldn't seem to find an answer to my questions. I am looking for a way to automate/script a set of SSH commands to export config files from our Sonicwall Routers. I have the sonicwall commands set but i am having trouble automating them. When I connect to one of our sonicwalls with SSH I get prompted with for a user. I type in the username and then get prompted again for a username and password. Once I enter the correct information, i can execute the export of the config. Below is an example of layout. Please let me know if anyone knows of a way to automate/script this. thanks in advance

User:%username%

User: %username%

Password: %password%

command: export preferences ftp %ftpserver% %ftpuser% %ftpPassword% backup.exp

4 Answers 4

1

Use keys instead of userid/password. http://pkeck.myweb.uga.edu/ssh/

Sign up to request clarification or add additional context in comments.

1 Comment

Will this work with routers (sonicwall). I read through the article you sent out and it only mentions server connections.
1

The router expects an SSH username, but not a password. Once you 'log in' with the username via SSH, the Sonicwall will prompt for a username and password using its internal authentication mechanism. Treat those prompts just like any other within the Sonicwall CLI. You can pass your commands (including username/password) via stdin like this, for example:

(echo -e 'admin\npassword'; sleep 1; echo tsr; sleep 2; echo logout; sleep 1) | ssh [email protected]

4 Comments

I am trying to use plink.exe (putty command line) to execute these commands and the code that you posted does not work. I slightly modified it to include the plink.exe before the -shh [email protected] address. The entire line "-e'admin\npassword'; sleep 1; echo tsr; sleep 2; echo logout; sleep 1)" gets displayed in the user prompt. From that point, the ssh session is non-responsive. How would you suggest I go about doing this? I finally have time to look back into this script and any help would be greatly appreciated.
The commands I provided were meant for the Linux bash shell. I would use plink on Windows like this: plink -ssh -l admin -m commands.txt 10.50.14.41 which will log you in and execute the commands in the file commands.txt. The first two commands in that file (one per line) should be the Sonicwall username and password, followed by whatever commands you want to issue. I haven't tried it, but in theory it should work.
Yeah I've tried that and it doesn't work. I receive a "FATAL ERROR: Server unexpectedly closed network connection" error message. If we can't get this to work with plink.exe, do you know of any other method I might be able to accomplish this using ssh and Windows OS? Thank you for all of your help.
I'm using Cygwin on Windows to do it -- the SSH client seems to work fine. Depending on the complexity of what you're trying to do, you might want to consider the Expect TCL extension link.
0

This thread is old but I finally got these stupid sonicwalls scripted. This isn't my code, I don't know where I found it but it works and you can make it do whatever. Just change the IP and login or whatever.

@if (@CodeSection == @Batch) @then

@echo on
set SendKeys=CScript //nologo //E:JScript "%~F0"

start \putty -ssh [email protected] 22

TIMEOUT /T 5
%SendKeys% "admin{ENTER}"
TIMEOUT /T 2
%SendKeys% "password{ENTER}"
TIMEOUT /T 2
%SendKeys% "restart{ENTER}"
TIMEOUT /T 2
%SendKeys% "y{ENTER}"

pause
@end

WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));

Comments

0

Try following.....

plink -ssh [email protected] < m.txt

< m.txt >

password

ping 1.1.1.1

tracerout 1.1.1.1

exit

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.