简体   繁体   中英

How can i give specific commands to programs via terminal Linux?

I'm seeking for a way to automatize the configuration of some tasks i do, but, i am having some trouble to give the order to the programs from the terminal.

I have actually to give, every time i try to configure some Routers, the same commands always and always, but, i'm looking for a way to create a Shell Script to do it for me. The problem, is. I must access a server with terminal to do that,so i can't give the commands as i always do, with terminal. I need a way to insert the commands inside the terminal.

This is the terminal i'm wanting to automatize 在此处输入图片说明

As you can see, i ways have to do the same commands, that would be pretty better, if the Shell Script, itself, did it for me.

Last but no least, there is a sample of what i tried to do:

#!/usr/bin/env bash
telnet 192.168.255.2 & < enable; show port epon 1/1 registered-link;
show port epon 1/2 registered-link; show port epon 1/3 registered-link;
show port epon 1/4 registered-link; show port epon 2/1 registered-link; 
show port epon 2/2 registered-link; show port epon 2/3 registered-link; 
show port epon 2/4 registered-link; show port epon 3/1 registered-link; 
show port epon 3/2 registered-link; show port epon 3/3 registered-link;
show port epon 3/4 registered-link; show port epon 4/1 registered-link;
show port epon 4/2 registered-link; show port epon 4/3 registered-link;
show port epon 4/4 registered-link; 

"telnet 192.168.255.2" is the server and the oders, are the commands it must do.

Anyway, thank you very much.

Fabric is your friend, designed exactly for that kind of task. http://www.fabfile.org/

You may use Fabric3 if you prefer Python 3. https://pypi.python.org/pypi/Fabric3

You appear to need the pexpect module , which is specifically designed for running commands on remote computers through teletype-like channels. It uses a pseudo-teletype device to present to the remote system pretty much as a standard user logging in to a shell. You can write scripts to scan for particular outputs, and it's often trivially easy using Python to generate the commands you want to run remotely.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM