Automation from Windows to Linux - Telnet and su using perl


 
Thread Tools Search this Thread
Operating Systems AIX Automation from Windows to Linux - Telnet and su using perl
# 1  
Old 01-20-2009
MySQL Automation from Windows to AIX - Telnet and su using perl

Here is my requirement to automate the deployment procedure for my project.
  1. Telnet to AIX box (say SERVER1) from windows machine (with USER1)
  2. Select the server to login say "SERVER2"
  3. su as different user say "USER2"(Owner of the deployed files)
  4. Execute the script (Script has so many functionality like ftp, changing permission, removing control-M, calling sub scripts)
  5. Exit from su environment
  6. Exit from telnet environment
Look at my perl Code :

use Net::Telnet;
my $telnet = new Net::Telnet(Timeout => 30,Errmode => 'die');
$telnet->open("SERVER1") or die "Connection failed $telnet->errmsg ";
print "connected\n";
$telnet->waitfor('/login: $/i');
$telnet->print("USER1") or die $telnet->errmsg;
$telnet->waitfor('/password: $/i');
$telnet->print("USER1-PASSWORD") or die $telnet->errmsg;
print "logged in first level\n";
$telnet->waitfor('/Enter Selection $/i');
$telnet->print("SERVER2") or die $telnet->errmsg;
print "Logged into SERVER2\n";
$telnet->cmd("touch test") or die $telnet->errmsg;
print "touch test executed\n";
==============###script is working till this part#####==========
$telnet->cmd("su - USER2");
$telnet->waitfor('Password: $/i');
$telnet->print("USER2-PASSWORD") or die $telnet->errmsg;
print "Logged in to USER2\n";
$telnet->cmd("sh script.sh") or die $telnet->errmsg;
print "successfully executed\n";
$telnet->cmd("exit");
$telnet->cmd("exit");

Limitation :
  1. I can't use SUDO or EXPECT. Because I am not the root user to use sudo. Expect is not installed in the server.
  2. Script has required permission to execute it from USER1 environment. But that script has to execute as USER2 else all files deployed will have USER1 as owner. This can be done using sudo, but this is very limited access environment, so I wont get access to sudo.
So I am looking for a su script sitting in USER1 environment to login without password and execute the script and exit from there.

Please let me know if there is any other possibility to get this work done.

Last edited by nurainos; 01-20-2009 at 09:33 AM.. Reason: Mistakenly typed Linux instead of AIX
# 2  
Old 01-20-2009
There's a Perl::Expect module at Expect.pm - Expect for Perl - search.cpan.org which works but suffers from limited documentation. Can you install the module on SERVER1 as USER1 and run a script from there to su to USER2?

Or can you run your deployment from a Linux system or an AIX system which *does* have Expect? All you seem to need to do is run the deployer script on SERVER1. Why does it matter that your driver system be Windows?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux VMguest Automation

i need a help to conigure the ipaddress for linux vmguest we have perl script to deploy the vmguest from our master server and that script will configure the vmguest and boot the machine automatically. i have query once guest booted it should read a file from (.vmx or some file from datestore... (0 Replies)
Discussion started by: venikathir
0 Replies

2. Shell Programming and Scripting

Automation SCRIPT to reset the password in PERL

Hi All, We have many number of users.Some times we will receive mail from them like , the below USER password got expired and they are requesting us to change the password and send it back to them in a mail. there we are giving Expiray date again. We are doing this process manually. I want... (2 Replies)
Discussion started by: vasuvv
2 Replies

3. Shell Programming and Scripting

EXPECT script for Telnet automation. Need your support.

Dear experts, please help me . I've found simple EXPECT scripts and all works fine. But I need more automation in error handling and sending list of commands/output logging from multiple remote hosts. I have 10 hosts, for example: host1 192.168.1.1 LOGIN1 PASSWORD1 ...... ... (2 Replies)
Discussion started by: starchen
2 Replies

4. UNIX for Dummies Questions & Answers

Need help configuring Active Perl on Windows Vista.: Perl Scripting on Windows

Hi All, Need help configuring Active Perl on Windows Vista. I am trying to install Active Perl on Windows Vista. The version of Active Perl i am trying to install is : ActivePerl 5.10.1 Build 1006 After installing it through cmd, When i try to run perl -v to check the version, i get the... (2 Replies)
Discussion started by: Vabiosis
2 Replies

5. UNIX for Dummies Questions & Answers

Help on Perl web automation

Hi All, Could experts in the forum suggest me a good book to create web based applications using Perl. Much thanks in advance Karthick (2 Replies)
Discussion started by: karthickrn
2 Replies

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

7. Shell Programming and Scripting

Web automation using perl

Hi all, I have to test a web application which has secure authorization. It is a ticketing site where I can create tickets,view and close them. I am trying to automate it in perl and I am not aware of how to do UI automation using perl. Please guide me in steps to implement a perl... (1 Reply)
Discussion started by: gurukottur
1 Replies

8. Cybersecurity

FTP Automation Windows <> Unix <> Remote

Hi All, I am a newbie to unix and scripting. I need to do the following job: 1. Create a batch file in windows that will call a script in a remote unix box. 2. The script now ftp files from the Remote windows machine and get them back to the local windows. Actually, I have written the script... (3 Replies)
Discussion started by: Ankur
3 Replies

9. UNIX for Dummies Questions & Answers

Automation of telnet and ftp

I have a basic query. I use telnet and ftp very frequently. I want to do it without spending time in typing username and password everytime. I know that if I have .netrc file which contains server address, username, pasword, then just typing ftp will conect to that server with that username and... (10 Replies)
Discussion started by: asutoshch
10 Replies
Login or Register to Ask a Question