-
How to execute telnet commands through a script?
I want to be able to set up a cronjob to telnet into my routers and perform some routine maintenance on them. Simple stuff that I do regularly and repetitively.
I know, it's a huge security risk, I'm willing to accept that.
So how do I go about setting up the scripts? I know that I use cron to pull a script that executes telnet, no problem. Where I get stuck is how do I do the scripting that enters the commands I need into that telnet session? It's going to be the same half dozen lines at each router. I just don't know how make what I would be typing if I was doing it manually seed the script and execute as part of the session. Any ideas?
-
You can try expect. Most distro's come with autoexpect installed.
autoexpect
(it will say created script.exp)
perform your commands, telnet, ftp, etc. Keep the commands generic, like mget * or mget *.txt kind of thing (i.e. if you get <todaysdate>.txt it would fail the next time the script is run).
Carry on, till done
exit
it will say writing script.exp
Then you simply
expect script.exp
and it will execute, and expect everything you just did.
NOTE: The telnet password will be plain text in the script, so, chmod 700 script.exp, you may want to encrypt it as well, and change it to a hidden file like .script.exp
hlrguy
-
If your routers are running sshd, you could write a script that used ssh commands.
You can also set up SSH Keys and run a key agent on your machine so you can log in without passwords.
Did you know that you can supply a command at the end of your ssh login command so that that command is executed and then you are logged out again?
It sounds perfect for what you want to do.
I use this set up at work (where I manage dozens of servers). Each morning, I just fire up my key agent and I can log into my servers quickly and easily.
It allows me to do things like
Code:
ssh -ladmin server.name.com ps aux
to quickly get a look at the process table on that machine.
If you did this, you could easily write a script that could do this kind of thing to multiple machines.
I learned how to set up SSH keys from an article at FedoraNews.org
-
Originally posted by hlrguy
NOTE: The telnet password will be plain text in the script, so, chmod 700 script.exp, you may want to encrypt it as well, and change it to a hidden file like .script.exp
But what's the point, when the script is going to send the password in plain text over the network anyway (telnet, remember)?
-
People who have actual access to your computer, or if it is networked in. There is a difference between sniffing it out the instant it is passed over the network as opposed to sitting in a plain text file, at least imho, . Personally, I use expect, but ssh instead of telnet.
hlrguy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|