Automation from Windows to Linux - 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.

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?