using shell script to telnet

Thread Tools Search this Thread
Operating Systems Solaris using shell script to telnet
# 1  
Old 01-16-2008
Data using shell script to telnet

I would like to log into a server read a certain file and get the results back. I have tried like below to no avail;

#!/bin/ksh -x

sleep 2
echo sdpuser
sleep 2
echo cs3reloaded
sleep 5
cd /export/home/scripts/daily_checks
sleep 5
head daily_check_report.txt > test160108.txt
) | telnet absdpb2
# 2  
Old 01-16-2008
I have had some success with a ksh coprocess. Example:
changepass automate password changes on multiple systems
# 3  
Old 01-16-2008
just for reading a file...
ftp -in<< EOF 
user anonymous
 get file  - 

# 4  
Old 01-16-2008
Use Netcat (in OpenSolaris based distributions) with -t flag to script telnet sessions.

More info about Netcat (nc(1)) in Solaris is here
# 5  
Old 01-16-2008
i was going to say netcat, but you could also do expect or perl.

do you want it to read real time, or just a one time process? i have a perl script that tails a file and writes the updates somewhere else if you'd like it.
# 6  
Old 01-16-2008
Most implementations telnet doesn't read from stdin. Also the way you have the code written, the file will be created on the system you are telneting to, not the one you are telneting from.

Easiest way on a modern unix box is to use ssh. (Should be included) and do something like this:
#!/bin/ksh -x

echo "
cd /export/home/scripts/daily_checks
head daily_check_report.txt
" | ssh absdpb2 > test160108.txt
If you add yourself to the authorized_keys on absdpb2 you won't even have to answer the userid and password question.

If ssh is not an option, then use the open source package expect. Google expect or "expect tcl" to learn more.
# 7  
Old 01-16-2008
Tools Some hints

First of all - telnet is not secure in any way. Try to use something different if possible.

You might want to check 'expect' - this could be useful for your purpose.

Try to avoid keeping passwords in the script files. I would advise SCP/SFTP with keys authentication. If this is not possible then FTP.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need shell script for SMS via telnet command

I am not very much familiar with telnet based scripting so I would need your help to directly submitting sms as deliver_sm or submit_sm msg to SMSC (IP & system_id and password are already known). So, need your help to provide such script. I previously used such script but my harddisk crashed and... (1 Reply)
Discussion started by: wasay
1 Replies

2. Shell Programming and Scripting

Using telnet in my shell script

Hello Guys, I have a linux server where I already logged in, once logged in, i telnet to local host using some dedicated port and do some action. This I can easily do manually. Since I need to fire a lot requests so I would like to optimize it using a shell script to avoid telnetting each... (3 Replies)
Discussion started by: umarsatti
3 Replies

3. UNIX for Dummies Questions & Answers

Shell Script to test telnet connection using port

Hello, I need to test telnet connections using port number for few hosts. Could you please help me? Thanks !! (1 Reply)
Discussion started by: skhichi
1 Replies

4. UNIX for Advanced & Expert Users

Telnet from shell script , further need to logout if log in not authenticate

Using unix shell script file I need to telnet to a IP further send a command to the telnet IP and get the response to a file with out using "expect" utility and I have achieved this by below command. (sleep 3; echo admin; sleep 3; echo mypass; sleep 5;echo "show status-list"; sleep 5; echo... (3 Replies)
Discussion started by: raghunath Rao
3 Replies

5. Shell Programming and Scripting

Telnet using shell script

Hi I need to telnet a device with IP Address and port. After logging in, I need to execute some commands in that device. Please find the example below telnet 2100 # is the IP address. 2100 is the Port after telnet, the device will show the command prompt as : ... (2 Replies)
Discussion started by: sudharsan23
2 Replies

6. Shell Programming and Scripting

How to Create a shell script to test the telnet connection status

Hi friends, I'm newbie to shell script. I wanted to create a shell script which able to write a result for all the telnet connection status. For example, from this machine I want to test the telnet connection (total 100+ servers) with this machine. Any idea how to write this shell script?... (16 Replies)
Discussion started by: yhcheong
16 Replies

7. Shell Programming and Scripting

closing a telnet session on error, in a shell script

I am using a shell script to telnet into a remote unix server and execute certain commands. But if any command being executed remotely, throws an error, the script just hangs. And the telnet session does not get closed. I want to be able to close the session and complete the script execution in... (1 Reply)
Discussion started by: farahzaiba
1 Replies

8. Shell Programming and Scripting

usage of telnet in shell script

Hi All, How could I use telnet to connect to Primary Host in the below shell script: Could I use: ( echo user sleep 2 echo password sleep 2 echo "ls ~" sleep 2 echo "exit" ) | telnet hostname ... (1 Reply)
Discussion started by: a1_win
1 Replies

9. Shell Programming and Scripting

telnet shell script on red hat 9 cmd line only

i would like to make a shell script (red hat 9 cmd line only) to telnet to my local isp's webmail server on port 25 and send it commands such as helo :) help would be much appreciated, and i found no posts similar that answered my question... the closest i've gotten to an answer from about 8... (3 Replies)
Discussion started by: kypeswith
3 Replies

10. Shell Programming and Scripting

telnet & su in shell script

Hi, Any scripting experts out there that can point me to the right direction of writing a script using telnet and su to access a server without any users interaction such as login and entering passwd. Thanks. Thanks in advance vastare (1 Reply)
Discussion started by: vastare
1 Replies
Login or Register to Ask a Question