
kotak86
New User
Jan 28, 2014, 8:39 PM
Post #1 of 7
(15702 views)
|
Execute Perl script on Remote server without any CPAN module
|
Can't Post
|
|
Hi I have Perl script (with set of system command in `sys command`). I wanted to run this script in other list of server that I can provide at the run time from my local server. Also I can not use Expect/ Net::SSH module or any other CPAN module. My script is running perfectly fine in my local machine, but when I have place the block of code, it seems it do not have reference to the script and can not perform any other line of code after doing ssh to the specific server. e.g. script name: servervalidation.pl my script should first take the server, and ssh to that server and then in that server login as su and then perform some set of command and get the information and send back to the local server from which I run he script. take argument: list_of_server File content :servera, serverb, serverc...... My script in local machine working fine. Please let me know if you need more information from my side. Thank you for reading my post and your help.
#!/usr/bin/perl use strict; use warnings; #use GetOpt::Long; use Data::Dumper; my $file = "NewPropertiesExample.txt"; open PROPERTIES, $file or die $!; my @properties = <PROPERTIES>; foreach my $prop (@properties){ if ($prop =~ m/^\[DISK_SETUP\]/){ my @disk_setup = split /\s+/, $prop; my @owner_rights = split/:/, $disk_setup[3]; my %Dsetup = ( $disk_setup[1] => { size => $disk_setup[2], owner => $owner_rights[0], group => $owner_rights[1], perm => $disk_setup[4] } ); my $disk_report = `df -h | grep -w "$disk_setup[1]" | tr -s [:space:]`; my @allocated = split /\s+/, $disk_report; my $group = getgrgid((stat $disk_setup[1])[5]); my $owner = getpwuid((stat $disk_setup[1])[4]); my $perm = `stat --format=%a $disk_setup[1]`; my $server_disk_size = $allocated[1]; my $perm_check = compare_perm($Dsetup{$disk_setup[1]}{perm}, $perm); my $size_check = compare_disk_allocation($Dsetup{$disk_setup[1]}{size}, $server_disk_size); print "The size for $disk_setup[1] is not matched\n", if $size_check == 0; print "The perm for $disk_setup[1] is not matched\n", if $perm_check == 0; foreach my $disk (keys %Dsetup) { print $disk, ":" ; foreach my $disk_para (keys %{$Dsetup{$disk}}){ print "\t$disk_para = $Dsetup{$disk}{$disk_para} \n"; } } } elsif ($prop =~ m/^\[SOFTWARE\]/){ # print "SOFTWARE line found => $prop"; } elsif ($prop =~ m/^\[CONFIG\]/){ # print "Configuration line found => $prop \n"; } } sub compare_disk_allocation { my $size_status = 0; my ($required_allocation, $server_allocation) = @_; $required_allocation =~ s/[A-Za-z]+//g; $server_allocation =~ s/[A-Za-z]+//g; $size_status =1, if ($required_allocation == $server_allocation); return $size_status; } sub compare_perm { my $perm_status = 0; my ($required_perm, $server_perm) = @_; $perm_status =1, if ($required_perm == $server_perm); return $perm_status; } Just sake for Information, cntent of property file is.....
[DISK_SETUP] /app 150GB own1:grp1 755 [DISK_SETUP] /logs 150GB own2:grp2 755 [DISK_SETUP] /home 35GB own3:grp3 755 [SOFTWARE] Introscope9.1.1 [SOFTWARE] AnthillPro3 [SOFTWARE] Apache Ant 1.8.4 [SOFTWARE] Apache Xalan (Java version) 2.7.1 [SOFTWARE] Oracle JRE 1.7.0_03 32bit [SOFTWARE] cRON [SOFTWARE] curl [SOFTWARE] expect [SOFTWARE] gzip [SOFTWARE] Postfix [SOFTWARE] tar [SOFTWARE] Tomcat 7.0.27 [CONFIG] ulimit 10000
(This post was edited by kotak86 on Jan 29, 2014, 8:09 AM)
|