use warnings;
use Getopt::Std;
-our ($opt_s, $opt_p, $opt_k, $opt_h);
-getopts('hs:p:k');
+our ($opt_s, $opt_r, $opt_k, $opt_h);
+getopts('hs:p:kr');
if($opt_h){
&showHelp();
&checkArgs();
+#--- on these PCs the script should be restarted:
+#my @PCList = ('lxg0429','lxg0433','lxg0435','lxg0437','lxg0439','lxg0440','lxg0441','lxg0442','lxg0443','lxg0444','lxg0445','lxg0446','lxg0447','lxg0448','lxg0452','lxg0453','lxg0454','lxg0455');
+my @PCList = ('lxg0447');
+my $args = "-d"; #- arguments of script to be restarted
+
&main();
exit(0);
-#---------------- END ---------------------
+#------------------------ END -------------------------
sub main
{
#--- on these PCs the script should be restarted:
- my @PCList = ('lxg0429','lxg0433','lxg0435','lxg0437','lxg0439','lxg0440','lxg0441','lxg0442','lxg0443','lxg0444','lxg0445','lxg0446','lxg0447','lxg0448','lxg0452','lxg0453','lxg0454','lxg0455');
-
+ #my @PCList = ('lxg0429','lxg0433','lxg0435','lxg0437','lxg0439','lxg0440','lxg0441','lxg0442','lxg0443','lxg0444','lxg0445','lxg0446','lxg0447','lxg0448','lxg0452','lxg0453','lxg0454','lxg0455');
+ my @PCList = ('lxg0447');
foreach my $PC (@PCList) {
print "restart on $PC ...\n";
- if($opt_k){
- #--- first kill then restart
+ if( $opt_k || $opt_r ){
+ #--- get PIDs of running scripts
my $command = "ssh $PC \"pidof -x $opt_s\" ";
my $out = `$command`;
chomp($out);
#--- is there anything to kill?
- if($out){
- system("ssh $PC \"pidof -x $opt_s | xargs kill -9; sleep 1; $opt_s -d\" ");
+ if($out && $opt_k){
+ #--- kill
+ system("ssh $PC \"pidof -x $opt_s | xargs kill -9\" ");
+ }
+ elsif($out && $opt_r){
+ #--- kill and restart
+ system("ssh $PC \"pidof -x $opt_s | xargs kill -9; sleep 1; $opt_s $args\" ");
}
- else{
- system("ssh $PC \"$opt_s -d\" ");
+ elsif($opt_r){
+ #--- restart
+ system("ssh $PC \"$opt_s $args\" ");
}
}
else{
#--- restart without killing
- my $command = "ssh $PC \"$opt_s -d\" ";
+ my $command = "ssh $PC \"$opt_s $args\" ";
system($command);
}
}
-s <name> : Name of script to be restarted. Name must
contain a path to a script on remote PC!
- -k : Try to kill a running script before restarting.
+ -r : Kill a running script before restarting.
+ -k : Kill a running script without restarting.
-h : Print this help.
EOF