Sponsored Content
Full Discussion: cat & telnet
Top Forums Shell Programming and Scripting cat & telnet Post 302420427 by Reboot on Tuesday 11th of May 2010 02:33:52 PM
Old 05-11-2010
To make a shell script which can telnet automatically and run commands on the other machine and end the telnet session without any interaction from the user, you need to install EXPECT and TCL packages on your unix system.

If you are done with above mentioned then, you can write a script similar to following (as per your requirements) :

Code:
#!/usr/local/bin/expect -f ####/usr/local/bin/expect is the directory where expect was installed 
log_user 0 ####this command is used to hide the conversationn between the script and the other machine 
set address [lindex $argv 0] ###assign the first passed parameter while calling the script to $address 
set username [lindex $argv 1] ###assign the 2nd passed parameter while calling the script to $username 
set password [lindex $argv 2] ###assign the 3rd passed parameter while calling the script to $password 
spawn telnet ${address} ###start the telnet session to machine with IP=$address 
###start conversation with the machine: 
expect "login:" 
send -- "${username}\r" 
expect "Password:" 
send -- "${password}\r" 
expect "$ " 
send -- "#!/bin/ksh\r" ###declare the shell to be used (optional) 
expect "$ " 
send -- "###type here any command you want to execute" 
expect "$ " 
send -- "exit\r" ###end the telnet session and exit the script


to execute this script, you can type:

Code:
$ expect_script "address" "username" "password" ###the script name is "expect_script"

but before u call the expect script, you should make the expect script executable, and this can be done by typing:
Code:
$ chmod +x expect_script

You can also call the above script from any other script....SmilieSmilie
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

rlogin & telnet

hi what is the main difference between rlogin and telnet? Or they are synonymous cheers (13 Replies)
Discussion started by: g-e-n-o
13 Replies

2. UNIX for Advanced & Expert Users

SCO OpenServer & telnet

I was wondering if anyone knew how I would open up my server so it can be telneted into from other subnets.:confused: (2 Replies)
Discussion started by: cparks73
2 Replies

3. Cybersecurity

telnet on AT&T MLS V

How do I enable telnet access to a system running AT&T MLS? (1 Reply)
Discussion started by: smartgod
1 Replies

4. 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

5. UNIX for Advanced & Expert Users

diable telnet & ftp

Hi All, I need to stop all the services for telnet & FTP as we want our server to be more secure. Please give me some steps for jumping to SSH protocol. How can i disable telnet & ftp service on my server. (1 Reply)
Discussion started by: pradeep_desh
1 Replies

6. Shell Programming and Scripting

cat & awk

Hi there, Can show some hit why i got this error? For eg i have a.txt in which consist of contents as below 1|781494-0015|IV\|I||C|RECHARGE|Success\|V\|\||2007-12-04 02:33:13.000| 2|762405-0405|IV\|I||C|RECHARGE|Success\|V\|\||2007-12-04 02:33:17.000| In fact , i want to perfrom to have... (2 Replies)
Discussion started by: rauphelhunter
2 Replies

7. Shell Programming and Scripting

for i in `cat myname.txt` && for y in `cat yourname.txt`

cat myname.txt John Doe I John Doe II John Doe III ----------------------------------------------------------------------- for i in `cat myname.txt` do echo This is my name: $i >> thi.is.my.name.txt done ----------------------------------------------------------------------- cat... (1 Reply)
Discussion started by: danimad
1 Replies

8. UNIX for Dummies Questions & Answers

Cat Input & Output to a Log file

Team, we use below command to store the contents in a logfile. cat a.txt > a.log a.txt content is 123 345 Is there any options available to store the command used also? for eg a.log may show as cat a.txt 123 345 (5 Replies)
Discussion started by: sid2013
5 Replies

9. Shell Programming and Scripting

Problem while displaying(cat) file content inside telnet loop .

Hi Team, Not getting the file output inside my email which i am sending from unix box. . Please refer the below code : #!/bin/sh { sleep 5 echo ehlo 10.56.185.13 sleep 3 echo mail from: oraairtel@CNDBMUREAPZP02.localdomain sleep 3 echo rcpt to: saurabhtripathi@anniksystems.com... (1 Reply)
Discussion started by: tripathi1990
1 Replies
telnetrc(4)							   File Formats 						       telnetrc(4)

NAME
telnetrc - file for telnet default options DESCRIPTION
The .telnetrc file contains commands that are executed when a connection is established on a per-host basis. Each line in the file con- tains a host name, one or more spaces or tabs, and a telnet(1) command. The host name, DEFAULT, matches all hosts. Lines beginning with the pound sign (#) are interpreted as comments and therefore ignored. telnet(1) commands are case-insensitive to the contents of the .telnetrc file. The .telnetrc file is retrieved from each user's HOME directory. EXAMPLES
Example 1: A sample file. In the following example, a .telnetrc file executes the telnet(1) command, toggle: weirdhost toggle crmod # Always export $PRINTER DEFAULT environ export PRINTER The lines in this file indicate that the toggle argument crmod, whose default value is "off" (or FALSE), should be enabled when connecting to the system weirdhost. In addition, the value of the environment variable PRINTER should be exported to all systems. In this case, the DEFAULT keyword is used in place of the host name. FILES
$HOME/.telnetrc SEE ALSO
telnet(1), in.telnetd(1M), environ(5) SunOS 5.10 9 Jan 1998 telnetrc(4)
All times are GMT -4. The time now is 03:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy