#!/bin/bash ###################################################################### ###### COMMANDWORM ############### ##################################################################### ########## This script facilitates various services that has ######### ##### to be performed by the administrator ##### ##################################################################### # Designed and Created by FAHAD SAEED on 13 JULY 2005 echo WELCOME TO COMMANDWORM ! # tests the last node that was able to ssh successfully and eliminated that # ip for further testing cat /home/admin/ip1>pool cat /home/admin/ip2>>pool cat /home/admin/ip3>>pool cat /home/admin/ip4>>pool #logged ip is the script in folder script1 that gets the ip of the last successful ssh bash /home/script1/loggedip # the ip of the machine is stored in the file /home/script1/ip read ipvar/home/admin/pool1 # now pool contains the ips that are to be analysed sed -n '1p' /home/admin/pool1>tar1 sed -n '2p' /home/admin/pool1>tar2 sed -n '3p' /home/admin/pool1>tar3 sed -n '4p' /home/admin/pool1>tar4 # If tar4 is empty then it means that adminworm was generated by another #node ELSE (if tar4 is not empty than) this is the first node that the admin # is using read target1nameofcommand echo $command>lastcommand else echo $command fi echo PLEASE WAIT ... echo It may take some time to execute the command !! echo # each node is checked weather the command is executed on the node or not #If NOT then the command is executed on that node and the same script is #executed on that node ######################################################################################### ################## command execution on first neighbour ########################## ssh admin@$target1 "scp /home/admin/lastcommand admin@$terminalip:/home/admin/rc" # Now the nameofcommand is in the /home/admin/rc,the last command executed on the remote #terminal read match < /home/admin/rc ## If rc is equal to the $command ,it means that the command has executed on the node ##else execute the command and initiate commandworm on that node if test "$match" = "$command" then echo The command has executed on $target1 else echo executing $command on $target1 ssh admin@$target1 "$command" scp /home/admin/nameofcommand admin@$target1:/home/admin scp /home/admin/lastcommand admin@$target1:/home/admin echo execution of $command on $target1 complete echo initializing commandworm on $target1 ssh admin@$target1 "bash /home/admin/commandworm" fi ######################################################################################### ################## execution of command on second neighbour ########################## ssh admin@$target2 "scp /home/admin/lastcommand admin@$terminalip:/home/admin/rc" # Now the nameofcommand is in the /home/admin/rc,the last command executed on the remote #terminal read match < /home/admin/rc ## If rc is equal to the $command ,it means that the command has executed on the node ##else execute the command and initiate commandworm on that node if test "$match" = "$command" then echo The command has executed on $target2 else echo executing $command on $target2 ssh admin@$target2 "$command" scp /home/admin/nameofcommand admin@$target2:/home/admin scp /home/admin/lastcommand admin@$target2:/home/admin echo execution of $command on $target2 complete echo initializing commandworm on $target2 ssh admin@$target2 "bash /home/admin/commandworm" fi ######################################################################################### ################## execution of command on third neighbour ###################### ssh admin@$target3 "scp /home/admin/lastcommand admin@$terminalip:/home/admin/rc" # Now the nameofcommand is in the /home/admin/rc,the last command executed on the remote #terminal read match < /home/admin/rc ## If rc is equal to the $command ,it means that the command has executed on the node ##else execute the command and initiate commandworm on that node if test "$match" = "$command" then echo The command has executed on $target3 else echo executing $command on $target3 ssh admin@$target3 "$command" scp /home/admin/nameofcommand admin@$target3:/home/admin scp /home/admin/lastcommand admin@$target3:/home/admin echo execution of $command on $target3 complete echo initializing commandworm on $target3 ssh admin@$target3 "bash /home/admin/commandworm" fi ######################################################################################### ################## execution of command on fourth neighbour ########################## if test "$target4" = "" # target 4 equal to null means that,target4 was the host of adminworm1. #this means that target4 has the required file and there even no need to #check the file in the remote machine then echo rm -f /home/admin/nameofcommand exit 0 else ssh admin@$target4 "scp /home/admin/lastcommand admin@$terminalip:/home/admin/rc" # Now the nameofcommand is in the /home/admin/rc,the last command executed on the remote #terminal read match < /home/admin/rc ## If rc is equal to the $command ,it means that the command has executed on the node ##else execute the command and initiate commandworm on that node if test "$match" = "$command" then echo The command has executed on $target4 else echo executing $command on $target4 ssh admin@$target4 "$command" scp /home/admin/nameofcommand admin@$target4:/home/admin scp /home/admin/lastcommand admin@$target4:/home/admin echo execution of $command on $target4 complete echo initializing commandworm on $target4 ssh admin@$target4 "bash /home/admin/commandworm" fi rm -f /home/admin/nameofcommand exit 0 fi rm -f /home/admin/nameofcommand exit 0