Sponsored Content
Top Forums Shell Programming and Scripting silent telnet and ssh using perl Post 302470028 by mtomar on Tuesday 9th of November 2010 03:19:55 AM
Old 11-09-2010
I Found solution atleast for telnet Smilie.. something is better than nothing .

Code:
#!/usr/bin/perl -w

use Net::Telnet; 

@nodeip = ("x.x.x.x","x.x.x.x") ;
%node = ("x.x.x.x","node1","x.x.x.x","node2") ;
foreach $nodeip (@nodeip) {
                          $telnet = new Net::Telnet ( Timeout=>10,Prompt=> '/.*@.*/',Errmode=>'die'); 
                          
                          $telnet->open($nodeip); 
                          $telnet->waitfor('/ogin: $/i'); 
                          $telnet->print('user); 
                          $telnet->waitfor('/assword: $/i'); 
                          $telnet->print('passwd'); 
                          print "========================================================\n";
                          print "            PERFORMING HEALTH CHECK ON $node{$nodeip}    \n";
                          print "========================================================\n";
                          
                          $telnet->waitfor('/# $/i');  
                                    
                         print "==================================\n";
                         print "Checking Basic system status::\n";
                         print "==================================\n";
                         @sysinfo1 = $telnet->cmd('uname -a');
                         @sysinfo2 = $telnet->cmd('uptime');
                         @sysinfo3 = $telnet->cmd('who -r');
                         
                         print "@sysinfo1  @sysinfo2  @sysinfo3","\n";
                         }

Trick was to define a prompt so that it does not get printed on your screen and to get rid of banner "waitfor" worked. I donno how .. but it worked may be someone can explain.

Following is output for this basic script.
Code:
========================================================
            PERFORMING HEALTH CHECK ON NODE1    
========================================================
==================================
Checking Basic system status::
==================================
SunOS eqm01s13p2 5.9 Generic_122300-34 sun4u sparc SUNW,Netra-CP2300
   11:17am  up 236 day(s),  6:44,  1 user,  load average: 1.51, 1.18, 1.16
     .       run-level 3  Mar 18 04:34     3      0  S

========================================================
            PERFORMING HEALTH CHECK ON NODE2    
========================================================
==================================
Checking Basic system status::
==================================
SunOS eqm01s14p2 5.9 Generic_122300-34 sun4u sparc SUNW,Netra-CP2300
   11:17am  up 217 day(s),  3:19,  3 users,  load average: 0.90, 0.91, 0.99
     .       run-level 3  Apr  6 08:00     3      0  S


Last edited by pludi; 11-09-2010 at 04:35 AM.. Reason: code tags, please...
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

silent telnet

I have been using the following code for sending out an email from a AIX UNIX platform. cat filename | telnet mailhost 25 >/dev/null Time to time I get a message loopback: A specified file does not support the ioctl system call. Can anyone tell me what this means? I need this function... (1 Reply)
Discussion started by: cgardiner
1 Replies

2. UNIX for Dummies Questions & Answers

telnet ans ssh

Hi all, I need few information as follows: 1. I am acessing one the machine uismg putty at port no 12023 using telnet service. My question is i heard by defalult the port for telnet is 23. Why it is 12023 in my case. Also where can i change it. 2. i install new debian server. And then... (1 Reply)
Discussion started by: gauri
1 Replies

3. UNIX for Advanced & Expert Users

about ssh and telnet

I amn't advance but i want to learn some commands where here you can help me. i don't learn easy commands but i learn if its good experience and interesting. I want to learn about ssh, telnet and how i can be miff ( i don't speek good english but i hope to understant me) thanks for any help... (1 Reply)
Discussion started by: Kostantinos
1 Replies

4. UNIX for Dummies Questions & Answers

like ssh telnet

I want to learn some commands like ssh, telnet and others where i can be tease. thanks for help... (2 Replies)
Discussion started by: Kostantinos
2 Replies

5. UNIX for Dummies Questions & Answers

Telnet and ssh in a script

dear all, I know that this question has been asked before frequently, but I really don't get it. My question is composed of several ones. First:To telnet through a script, I was told to use the way described below, and it works for me, but i don't understand the syntax here.... (3 Replies)
Discussion started by: marwan
3 Replies

6. Shell Programming and Scripting

[Perl] Silent Input

I would like to use the WWW::Mechanize module to access a webpage that is password-protected. I was wondering if there was a way to make the input silent when asked from the script. For example: What is your password: <password> Where <password> is where you put your password, but is silent... (2 Replies)
Discussion started by: eightysix
2 Replies

7. Shell Programming and Scripting

Webpage to Telnet via Perl and Expect: Telnet problem?

Somewhat long story: I have a simple Perl CGI script that uses Expect to Telnet to a device and grab some data, and then spits it back to Perl for display on the Webpage. This works for many devices I've tried, but one device just fails, it keeps rejecting the password on this device, only... (1 Reply)
Discussion started by: jondo
1 Replies

8. Shell Programming and Scripting

TELNET to SSH

Hi All, I was implementing a change of TELNET to SSH connectivity, and finding it tough at a point where I was connecting to another unix server through TELNET. ( ps -ef |grep abcd) | TELNET x.xx.xxx.xx now I when I tried to replace TELNET with SSH, i am not able to connect. ( ps -ef... (1 Reply)
Discussion started by: pranavagarwal
1 Replies

9. AIX

Problems with SSH / telnet

Hey, I have upgraded 3 servers from SSH Tectia 4.0.3 to SSH Tectia 6.0.2. 2 of them are working fine but one server suddenly began to have troubles after about 2 hours. Now it is impossible to login to this server using SSH and even telnet. When SSH is running on this particular server, the CPU... (20 Replies)
Discussion started by: Hille
20 Replies

10. Shell Programming and Scripting

silent Input in PERL

Hello Experts, I am learning perl. I know ksh/bash/csh... In ksh I use to do this way... to read user input in silent mode so that nothing returns on the screen. stty -echo read -r pswd stty echo Please let me know the way in perl how to do it. Here are my OS and Perl Details... ... (3 Replies)
Discussion started by: explorer007
3 Replies
SHELL-QUOTE(1)						User Contributed Perl Documentation					    SHELL-QUOTE(1)

NAME
shell-quote - quote arguments for safe use, unmodified in a shell command SYNOPSIS
shell-quote [switch]... arg... DESCRIPTION
shell-quote lets you pass arbitrary strings through the shell so that they won't be changed by the shell. This lets you process commands or files with embedded white space or shell globbing characters safely. Here are a few examples. EXAMPLES
ssh preserving args When running a remote command with ssh, ssh doesn't preserve the separate arguments it receives. It just joins them with spaces and passes them to "$SHELL -c". This doesn't work as intended: ssh host touch 'hi there' # fails It creates 2 files, hi and there. Instead, do this: cmd=`shell-quote touch 'hi there'` ssh host "$cmd" This gives you just 1 file, hi there. process find output It's not ordinarily possible to process an arbitrary list of files output by find with a shell script. Anything you put in $IFS to split up the output could legitimately be in a file's name. Here's how you can do it using shell-quote: eval set -- `find -type f -print0 | xargs -0 shell-quote --` debug shell scripts shell-quote is better than echo for debugging shell scripts. debug() { [ -z "$debug" ] || shell-quote "debug:" "$@" } With echo you can't tell the difference between "debug 'foo bar'" and "debug foo bar", but with shell-quote you can. save a command for later shell-quote can be used to build up a shell command to run later. Say you want the user to be able to give you switches for a command you're going to run. If you don't want the switches to be re-evaluated by the shell (which is usually a good idea, else there are things the user can't pass through), you can do something like this: user_switches= while [ $# != 0 ] do case x$1 in x--pass-through) [ $# -gt 1 ] || die "need an argument for $1" user_switches="$user_switches "`shell-quote -- "$2"` shift;; # process other switches esac shift done # later eval "shell-quote some-command $user_switches my args" OPTIONS
--debug Turn debugging on. --help Show the usage message and die. --version Show the version number and exit. AVAILABILITY
The code is licensed under the GNU GPL. Check http://www.argon.org/~roderick/ or CPAN for updated versions. AUTHOR
Roderick Schertler <roderick@argon.org> perl v5.16.3 2010-06-11 SHELL-QUOTE(1)
All times are GMT -4. The time now is 04:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy