BASH + Telnet

Status
Not open for further replies.

Greg

Indeed.
Messages
1,600
I want to write a bash script that will telnet into my modem and perform a set of commands, but I'm not really sure where to start in writing this script. Is this even possible? Any help is appreciated.

Thanks,
~Greg
 
Hmm... I know you could write a script to telnet into your modem. And I know you could write a script that would execute a set of commands.

I just don't know if it would work to have them in one. :(

horndude would know, I think.

[/end useless post] :eek:
 
Just to clarify, when I say "telnet into my modem and perform a set of commands" I mean the commands would be performed on the modem through telnet. I don't really need to have any commands executed on my computer.

I'm glad to see you're still around here, and thanks for the response.

~Greg
 
Ah, yes! I got it. I found this website which had an example that I based mine off of.

I always hate those web activity logs for some reason, even though I know nobody else can see them :p The purpose of this script is remove the log from my modem and replace it with a link to /dev/null so it can't be regenerated.


I start this script:
Code:
#!/bin/bash
echo -n "Password: "
./telnet-commands | telnet
which executes this script:
Code:
#!/bin/bash

stty_orig=`stty -g`
stty -echo
read pass
stty $stty_orig

echo "open 192.168.100.1 23"
sleep 1
echo "admin"
sleep 1
echo ${pass}
sleep 1
echo "cd /var/tmp"
sleep 1
echo "rm log_web_activity"
sleep 1
echo "ln -s /dev/null log_web_activity"
sleep 1
echo "exit"
and pipes it into telnet.

I'm happy, no more doing it by hand :)
 
Glad to see it helped someone, I love futzing around with Bash scripts :)

I'm still pretty bad at writing them, but it's always fun.
 
^ OMG there's someone else in Bakersfield who uses Linux and likes Star Trek. Are you sure you aren't me? lol :p
 
You do realise that telnet doesn't encrypt. For remote login, use SSH, its more secure.

If you used SSH you could write

Code:
ssh username@ipaddress ./telnet_commands.sh

to excute a command or shell script on the remote computer. With the script being

Code:
#!/bin/bash
cd /var/tmp
rm log_web_activity
ln -s /dev/null log_web_activity

A good tutorial for SSH is here
 
Status
Not open for further replies.
Back
Top Bottom