Here is my requirement to automate the deployment procedure for my project.
- Telnet to AIX box (say SERVER1) from windows machine (with USER1)
- Select the server to login say "SERVER2"
- su as different user say "USER2"(Owner of the deployed files)
- Execute the script (Script has so many functionality like ftp, changing permission, removing control-M, calling sub scripts)
- Exit from su environment
- 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 :
- I can't use SUDO or EXPECT. Because I am not the root user to use sudo. Expect is not installed in the server.
- 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.