#!/bin/bash ###################################################################### ###### FILEWORM ############### ##################################################################### ########## This script facilitates various services that has ######## ##### to be performed by the administrator ##### ##################################################################### # Created by FAHAD SAEED on 25 june 2005 # Designed by FAHAD SAEED & FAHAD ALI ARSHAD echo WELCOME TO FILEWORM ! # 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 target1nameoffile else echo $filename fi echo $filename echo PLEASE WAIT ... echo It may take some time to transfer the file !! echo # each node is checked weather it has the file present or not #If the file is not in the remote /home/admin then the file is #transfered and the same script is initiated on that node ######################################################################################### ################## transfer of file to first neighbour ########################## ssh admin@$target1 " ls home/admin >/home/admin/log" ssh admin@$target1 "scp /home/admin/log admin@$terminalip:/home/admin/" #Now the files that are in the remote /home/admin are in the local #terminal /home/admin/log file grep $filename /home/admin/log >/home/admin/present read match < /home/admin/present if test "$match" = "" then echo $target1 does not contain the file $filename echo transfering file $filename scp /home/admin/$filename admin@$target1:/home/admin/ scp /home/admin/nameoffile admin@$target1:/home/admin echo transfer of $filename to $target1 complete echo initializing fileworm on $target1 ssh admin@$target1 "bash /home/admin/fileworm" else echo $filename in $target1 already present fi ######################################################################################### ################## transfer of file to second neighbour ########################## echo Entering the second target ssh admin@$target2 "ls /home/admin >/home/admin/log" ssh admin@$target2 "scp /home/admin/log admin@$terminalip:/home/admin/" #Now the files that are in the remote /home/admin are in the local #terminal /home/admin/log file grep $filename /home/admin/log >/home/admin/present read match < /home/admin/present if test "$match" = "" then echo $target2 does not contain the file $filename echo transfering file $filename scp /home/admin/$filename admin@$target2:/home/admin/ scp /home/admin/nameoffile admin@$target2:/home/admin echo transfer of $filename to $target2 complete echo initializing fileworm on $target2 ssh admin@$target2 "bash /home/admin/fileworm" else echo $filename in $target2 already present fi ######################################################################################### ################## transfer of file to third neighbour ########################## echo Entering the third target ssh admin@$target3 "ls /home/admin >/home/admin/log" ssh admin@$target3 "scp /home/admin/log admin@$terminalip:/home/admin/" #Now the files that are in the remote /home/admin are in the local #terminal /home/admin/log file grep $filename /home/admin/log >/home/admin/present read match < /home/admin/present if test "$match" = "" then echo $target3 does not contain the file $filename echo transfering file $filename scp /home/admin/$filename admin@$target3:/home/admin/ scp /home/admin/nameoffile admin@$target3:/home/admin echo transfer of $filename to $target3 complete echo initializing fileworm on $target3 ssh admin@$target3 "bash /home/admin/fileworm" else echo $filename in $target3 already present fi ######################################################################################### ################## transfer of file to 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 rm -f /home/admin/nameoffile exit 0 else ssh admin@$target4 "ls /home/admin >/home/admin/log" ssh admin@$target4 "scp /home/admin/log admin@$terminalip:/home/admin/" #Now the files that are in the remote /home/admin are in the local #terminal /home/admin/log file grep $filename /home/admin/log >/home/admin/present read match < /home/admin/present if test "$match" = "" then echo $target4 does not contain the file $filename echo transfering file $filename scp /home/admin/$filename admin@$target4:/home/admin/ scp /home/admin/nameoffile admin@$target4:/home/admin rm -f /home/admin/nameoffile echo transfer to $filename to $target4 complete echo initializing fileworm on $target4 ssh admin@$target4 "bash /home/admin/fileworm" else rm -f /home/admin/nameoffile echo $filename in $target4 already present exit 0 fi fi exit 0