Sponsored Content
Top Forums Shell Programming and Scripting How to run scripts within a telnet session? Post 302746629 by Chubler_XL on Wednesday 19th of December 2012 07:59:37 PM
Old 12-19-2012
You could try an expect script

Something like this should do it, command are in text file cmd_file in current directory output files are good_result_log and bad_result_log:


Code:
#!/usr/bin/expect -f
set timeout 2
spawn -noecho telnet remotehost
log_user 0
 
# Change command prompt to "PROMPT# " to make matching safer
send "PS1='PROMPT# '\r"
expect -re "PROMPT# '(.*)PROMPT# "
 
#Open Input and Output files
set cmds [open cmd_file r]
set eout [open bad_result_log w]
set gout [open good_result_log w]
 
while {[gets $cmds command] >= 0} {
    send "$command\r"
    expect -re "\r\n(.*)\r\n(.*)PROMPT# "
    set output $expect_out(1,string)
    if {[regexp {OK} $output match] == 1} {
       puts $gout $output
    } else {
       puts $eout $output
    }
}
 
close $cmds
close $eout
close $gout
 
send "exit\r"
expect eof

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Uploading and Downloading during a telnet session

Hi there, I'm trying to download files from a server and also upload new files to the same server during a telnet session. How do I go about getting certain files (.gif) from the server onto my local drive and vice versa? Can anyone help me? Thank you so much! (1 Reply)
Discussion started by: WhitneyMay
1 Replies

2. UNIX for Dummies Questions & Answers

telnet session timeout

hi, we can set something such that if the user has been idle for a while, it will auto disconnect. where to do so? thanks (6 Replies)
Discussion started by: yls177
6 Replies

3. Shell Programming and Scripting

Telnet session does not expire

Dear friends.. Our project has a module that runs on handheld devices. Through the handheld we telnet to solaris where the application actually runs. I noticed that after starting a session through the handheld, if i go out of range or if i remove and replace the battery in the handheld, the... (1 Reply)
Discussion started by: deepsteptom
1 Replies

4. Shell Programming and Scripting

Telnet Session

{ sleep 2 echo "$user" sleep 2 echo "$password" sleep 2 echo " ls" sleep 10 echo "exit" }| telnet $server I have a machine x and i have executed the above script on machine 'x'. i entered the... (6 Replies)
Discussion started by: pathanjalireddy
6 Replies

5. UNIX for Dummies Questions & Answers

Unix Telnet session

Hi Is there any way whilst in a telnet session you can view your client machine name that you are using to connect to the Unix box ? :eek: (2 Replies)
Discussion started by: mlucas
2 Replies

6. UNIX for Dummies Questions & Answers

Telnet Session to AIX

Hello, I have AIX 5.3 at home connected to netgear router. Port Forwarding has been enabled on the router. Problem is that if I want to telnet, I have to try 2 or 3 times before I can get a logon prompt. It times out for first or second time (Connection to session <IP_Address> failed: Connection... (1 Reply)
Discussion started by: bluebee
1 Replies

7. UNIX for Dummies Questions & Answers

Disconnecting a telnet session

How can I disconnect an existing telnet session? The host is a serial port server with multiple ports. The users login using the host's name and a port, i.e. telnet host01 1235. Thanks. (14 Replies)
Discussion started by: cooldude
14 Replies

8. Shell Programming and Scripting

telnet and run scripts

Hello folks, I've got this script which connects to different boxes and executes a certain script in those locations. The following is the line from where i am trying to do this: (sleep 1; echo $USERID ; sleep 1; echo $PASSWD ; sleep 1 ; echo y ; sleep 1 ; echo "\r" ; sleep 1 ; echo "cd... (1 Reply)
Discussion started by: Rajat
1 Replies

9. HP-UX

ssh session getting hung (smilar to hpux telnet session is getting hung after about 15 minutes)

Our network administrators implemented some sort of check to kill idle sessions and now burden is on us to run some sort of keep alive. Client based keep alive doesn't do a very good job. I have same issue with ssh. Does solution 2 provided above apply for ssh sessions also? (1 Reply)
Discussion started by: yoda9691
1 Replies
gout(1) 						       Scotch user's manual							   gout(1)

NAME
gout - output graphics from matrices and graphs SYNOPSIS
gout [options] [gfile] [xfile] [mfile] [vfile] DESCRIPTION
The gout program creates graphics files of various types, representing the Scotch graph and mapping data which is passed to it. Source graph file gfile can only be a centralized graph file. File xfile stores its associated geometry, whenever necessary. File mfile represents label information attached to each of the graph vertices, for instance the index of the part to which each vertex belongs in the case of a mapping file. File vfile is the output graphics file, the type of which may differ according to the input parameters. When file names are not specified, data is read from standard input and written to standard output. Standard streams can also be explicitly repre- sented by a dash '-'. When the proper libraries have been included at compile time, gtst can directly handle compressed graphs, both as input and output. A stream is treated as compressed whenever its name is postfixed with a compressed file extension, such as in 'brol.grf.bz2' or '-.gz'. The compression formats which can be supported are the bzip2 format ('.bz2'), the gzip format ('.gz'), and the lzma format ('.lzma', on input only). OPTIONS
-h Display some help. -ggeop Geometry parameters, which can be an arbitrary combination of any of the following code letters: n Do not read geometry data, when it is not available or not required, such as when using the -om option. p Permute Y and Z geometry dimensions. r Rotate geometry by 90 degrees in the (X,Y) plane. -h Display some help. -mn Do not read mapping data, when it is not available or not required. -ooutp Select the output file type and allows to provide additional parameters between braces and separated by commas: i OpenInventor 3D mesh file, to be viewed by means of programs such as ivview. Additional parameters for this output file type are: c Color output. g Gray level output. r Remove cut edges. v View cut edges. m PostScript matrix pattern file. Additional parameters for this output file type are: e EPSF-type output. f Full-page output. p PostScript 2D mesh file. This output module was intended for 2D meshes; as a fallback, the Z coordinate is projected accord- ing to isometric perspective rules, but drawings of full 3D objects are most likely to be unreadable. Additional parameters for this output file type are: c Color output. g Gray level output. e EPSF-type output. f Full-page output. s Short clipping (disks excluded). l Large clipping (disks included). a Avoid displaying disks. d Display disks. r Remove cut edges. v View cut edges. X=rat Maximum x clipping ratio (in [0.0;1.0]). x=rat Minimum x clipping ratio. Y=rat Maximum y clipping ratio. y=rat Minimum y clipping ratio. t Tulip 3D mesh file. Additional parameters for this output file type are: b Black and white output. c Color output. a Avoid displaying disks. d Display disks. r Remove cut edges. v View cut edges. -V Display program version and copyright. EXAMPLES
Build an OpenInventor file of the mapping of graph brol.grf contained in file brol.map. Vertices with no mapping information attached to them will be rendered in white, while distinct colors will be used to represent the different parts. Cut edges will be removed: $ gout '-oi{r}' brol.grf brol.xyz brol.map brol.iv $ ivview brol.iv Build an OpenInventor file of graph brol.grf without any vertex information associated to it. Mapping data are not required and will not be read, but a file name has to be provided, hence the '-': $ gout -oi -mn brol.grf brol.xyz - brol.iv Output the pattern of matrix brol.grf on the form of a PostScript flat drawing. Geometry and mapping data are not required and will not be read, but file names have to be provided, hence the two '-'s: $ gout -om -gn -mn brol.grf - - brol.ps Output a PostScript 2D drawing of a rectangular portion graph brol.grf, with disks representing mapping data: $ gout '-op{c,e,d,x=0.3,X=0.6,y=0.2,Y=0.5}' brol.grf brol.xyz brol.map brol.ps SEE ALSO
gmap(1), gout(1), gtst(1). Scotch user's manual. AUTHOR
Francois Pellegrini <francois.pellegrini@labri.fr> August 03, 2010 gout(1)
All times are GMT -4. The time now is 09:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy