##rsh_cluster_update.pl ##to execute this script either save it off on your machine and execute it with the command "perl rsh_cluster_update.pl (or whatever you call it) ##or copy this segment to the first line "#!/usr/bin/perl -w", exactly as is, make the file executable, and execute it. ##this version of the cluster update script is intended to be run when using rsh as the communication tool within the cluster. unlike the version ##used under ssh, it doesn't use perl modules to accomplish copying and remote restarting of the mosix daemons, but directly calls the system ##rcp and rsh commands with appropriate commands. i actually prefer the module approach for portability and elegance, but there don't seem to ##any modules that directly pertain to rcp, and portability between operating systems is not a major concern in this context. use strict; use Socket; ##mfs mount point scalar my $mfs_mount='//mfs'; ##configuration file repository path my $source_dir = '//home//mosix//'; ##open a directory handle to the mfs mount point opendir(MFS_HANDLE,$mfs_mount); ##array to hold the directories under the mount point and a scalar to hold the current array member as the script iterates over the array. my @mfs_dirs; my $mfs_dirs; ##read the contents of the directory handle into the array @mfs_dirs=readdir MFS_HANDLE; ##the following scalar will hold the results of mosctl commands after they are written to files by the executed command my $response; ##this scalar holds the full path version of the restart command, relative to the root of whatever machine is pertinent my $restart = '//etc/init.d//mosix restart'; ##scalar to hold the results of the test conducted during the array iteration my $testvar; ##the following 3 scalars hold the fully qualified names of the configuration files being distributed my $map_file=$source_dir.'mosix.map'; my $hosts_file=$source_dir.'hosts'; my $default_mosix_file=$source_dir.'mosix'; ##the following three scalars will hold the destination file name when they are constructed within the loop my $dest_map_file; my $dest_hosts_file; my $dest_default_mosix_file; ##this scalar will hold the binary address of the relevant host my $addr; ##array to hold the information returned by the gethostbyaddr() function my @host; ##scalar to hold the hostname, first element of the array returned by the gethostbyaddr() function my $host; ##for each element of the @mfs_dirs array (for each directory under /mfs) foreach $mfs_dirs(@mfs_dirs) { ##$testvar is true if the dirctory name contains a digit $testvar=($mfs_dirs=~/^\d/); ##if $testvar is true ... if ($testvar) { ##it is possible that since the cluster controller (re)started mosix a machine that was in the cluster is no longer there, ##for whatever reason. to prevent that from breaking the script execution, we'll check to make sure that machine is up. ##execute the mosctl command with the isup argument and the mosix number of the machine, which is what the directory ##number represents, and write the result to a file system("mosctl isup $mfs_dirs > mos_stat"); ##open a read file handle on the result of the operation above open(STATUS,'; ##if the machine is up ... if ($response=~/yes/) { ##determine the hostname of the machine by executing the mosctl command with the whois option, and write the ##response to a file system("mosctl whois $mfs_dirs > mos_host"); ##as above, open a file handle on the resultant file and read in the only line there open(HOST,'; ##convert the returned address to packed binary representation $addr=inet_aton($response); ##use that representation to get the host information @host=gethostbyaddr($addr, AF_INET); ##store the first element of that array into the $host scalar $host=$host[0]; ##construct three scalars holding the destination files $dest_map_file="root@".$host.":/etc/mosix/mosix.map"; $dest_hosts_file="root@".$host.":/etc/hosts"; $dest_default_mosix_file="root@".$host.":/etc/default/mosix"; ##execute the copying operations system("rcp $map_file $dest_map_file"); system("rcp $hosts_file $dest_hosts_file"); system("rcp $default_mosix_file $dest_default_mosix_file"); ##execute the restart command system("rsh $host $restart"); close(HOST); system("rm mos_host"); } close(STATUS); system("rm mos_stat"); } }