How to answer the Questions in Perl .


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to answer the Questions in Perl .
# 1  
Old 11-25-2008
How to answer the Questions in Perl .

I need to write a script to telnet or ssh a device the execute some commands in device then copy the output in a file, I wrote the script but I faced one issue, when you execute some commands the device asked me a Question, for example :
device # copy run tftp
device # Source filename [running-config]?

then the script hang, my Question is how to pass the answers to device using perl ??
# 2  
Old 11-25-2008
Google "here document in perl".

If you are using shell you can use a here document too, or use the yes command and pipes. yes "answer" |"command expecting answer".

You can give yes multiple answers, like yes "y y y" |...
# 3  
Old 11-26-2008
Thanks a lot for your reply
May you please explain me more with examples,
This is my telnet script :
Code:
#!/usr/local/bin/perl
$ip       = $ARGV[0];
die ("IP must be passed as an argument. $!\n") unless defined($ip);
use Net::Telnet ();
$handle = new Net::Telnet (Timeout => 10, Prompt => '/.*(#|>|\))\s*$/');
$handle->open("$ip"); 
$handle->login("Username","password");
$handle->cmd("terminal length 0");
@lines = $handle->cmd(" ANY COMMAND HERE NEED ANSWER");
print "@lines";
$handle->cmd(exit);
$handle->close;

# 4  
Old 11-30-2008
any help Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Solaris

==please answer the following questions==

Hello :) ! i've few doubts. 1) how can we find the newly attached disk in SOLARIS ? 2) how to change port number of a service ? 3) how can we find that autofs is running in our system without using svcs and prstat commands ? 4) we know that there are several types of dns servers in... (0 Replies)
Discussion started by: vamshigvk475
0 Replies

2. UNIX for Dummies Questions & Answers

Need answer for these LINUX questions URGENT!!

I am very new to LINUX and could not find answer to these questions please submit your comments and suggestions to answer these questions. Appreciate your time thank you, :) 1. Make sure there is no filename1.txt in current directory first. Now, enter vi with "vi filename1.txt" command. vi... (4 Replies)
Discussion started by: linux17
4 Replies

3. UNIX for Dummies Questions & Answers

Need answer for these LINUX questions URGENT!!

I am very new to LINUX and could not find answer to these questions please submit your comments and suggestions to answer these questions. Appreciate your time thank you, :) If you look at the permissions associated with a symbolic link, it has universal access. Does this lead to security... (0 Replies)
Discussion started by: linux17
0 Replies

4. Solaris

Please give me answer for these interview questions.

As i'm going to attend my first interview day after tomorrow, What should i need to answer if the interviewer asked me about 1. Tell me about your production environment. 2. What about your team size? 3. Tell me about the most critical situation/issue you have ever faced. Can any... (10 Replies)
Discussion started by: Sesha
10 Replies

5. UNIX for Dummies Questions & Answers

can any one please answer these questions

6.nohup cmn is used to Prot execn of pgm frm aborting when hangup s/g is rxd Not hangup modem Disconn a node frm s/m Chng execn prev of pgm .wat is the o/p? Cut -d”” -f3 file1/sort -r Display 3rd col of file 1 in asc order Disp 3rd col of file 1 in desc Not ... (1 Reply)
Discussion started by: techguru
1 Replies

6. UNIX for Dummies Questions & Answers

Unix Experts Answer this INterview Questions please

1, why Boot server should be in a network in jumpstart? 2, what is the different between patch and package? 3, how to list the avilable NIC in solaris9? 4, User complaing system is slow (solaris) what are the steps to check? 5, what is hardware error and software error and Transport Error? in... (5 Replies)
Discussion started by: suresh_krish
5 Replies

7. Shell Programming and Scripting

Answer Terminal Questions With Shell Script?

First off, I am using Mac OS X, with Apple Remote Desktop. I have to install several app's on teachers' laptops which are on several cd's that I have made disk images of. (DMG's) To do rollouts quicker, I have written a script to mount the disk images and running the installers inside each of... (4 Replies)
Discussion started by: The Reepr
4 Replies

8. UNIX for Dummies Questions & Answers

urgent- please answer these set of questions

Hi, I have a few questions to be answered.Please help me out in this.Its urgent. 1) what does ' $* ' mean, what does it do ? 2) Command to change UNIX Password. 3) What is Daemon processes ? 4) How do u execute a Unix command or process in the background ? 5) What is nohup ? 6) Difference... (6 Replies)
Discussion started by: uni_ajay_r
6 Replies
Login or Register to Ask a Question