--- /dev/null
+#!/usr/bin/perl -w
+
+########################################################
+# restart script on a given list of PCs #
+# #
+# Sergey Yurevich #
+########################################################
+
+use strict;
+use warnings;
+use Getopt::Std;
+
+our ($opt_s, $opt_p, $opt_k, $opt_h);
+getopts('hs:p:k');
+
+if($opt_h){
+ &showHelp();
+ exit(0);
+}
+
+&checkArgs();
+
+&main();
+
+exit(0);
+
+#---------------- 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');
+
+
+ foreach my $PC (@PCList) {
+
+ print "restart on $PC ...\n";
+
+ if($opt_k){
+ #--- first kill then restart
+ 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\" ");
+ }
+ else{
+ system("ssh $PC \"$opt_s -d\" ");
+ }
+ }
+ else{
+ #--- restart without killing
+ my $command = "ssh $PC \"$opt_s -d\" ";
+ system($command);
+ }
+ }
+}
+
+sub checkArgs
+{
+ if( !defined($opt_s) ){
+ print "You must provide -s option with arguments!\n";
+ print "Read help: restart.pl -h\n";
+ exit(0);
+ }
+}
+
+sub showHelp
+{
+ print << 'EOF';
+
+ Restart Script
+
+ This script restarts a script given as an argument.
+ The script is restarted on a list of machines listed
+ in @PCList array. Password-less SSH is used to login
+ to remote PCs, thus, you must set up private/public keys!
+ The remote script will be restarted under your 'user name'.
+
+ Usage: restart.pl -s <name> [-k] [-h]
+
+ -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.
+ -h : Print this help.
+
+EOF
+}