Perhaps a python script would work for this simple automation. I need to connect via ssh to my router and run a command over and over. I understand that if I use Plink with a script I will probably have to repeat my command thousands of times. That would work but isn't there a better to just simply repeat the command?
For example, if i have to make a script my file would look like this:
/user/print
/user/print
/user/print
/user/print
/user/print
/user/print
/user/print
.....
To do the loop on the server-side do:
plink username@example.com "while true; /user/print; done"
This has an advantage that you connect only once to the server.
To do the loop on the client-side do:
:loop plink username@example.com /user/print goto loop
See also How to create an infinite loop in Windows batch file?
If you can do Python, just loop the ssh.exec_command
call.
import paramiko import time ssh = paramiko.SSHClient() ssh.connect("example.com", username="username", password="password") while True: print "Running" stdin, stdout, stderr = ssh.exec_command("/log print") print stdout.read() print stderr.read() print "Waiting" time.sleep(5)
The above is combined code from:
You can use the vassal package, which is exactly designed for this.
All you need is to install vassal and do
from vassal.terminal import Terminal
from vassal.scheduler import Scheduler
shell = Terminal(["ssh username@host", "cd scripts", "python foo1.py", "python foo2.py"])
shell = Scheduler(shell, sec=1)
shell.run()
This will run the command once every second, and you can make it run faster to change sec=0.1.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.