Need to create a simple script using MD5, SSH...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to create a simple script using MD5, SSH...
# 29  
Old 03-08-2011
Well, if it's printing "ssh-ing to box rtidsva", it must be pulling that name from somewhere, so I think it really is executing those two programs and reading the names appropriately.

I assume this 'first' variable is to compare all following with the local host. Why not do that separately to avoid confusion and cut a big chunk of extra logic out?

Code:
#!/usr/bin/sh 
 
while read fname; do 
    bname=$(basename $fname) 
    echo "trying "${fname} (${bname})" >&2

    hash=$(/usr/local/bin/md5 /opt/dba/scp/$bname | awk '{print $4}')

    echo "local hash is ${hash}"

    /usr/local/bin/hosts | while read box ; do 
        echo "ssh-ing to box ${box}" >&2
        t=$(ssh ${box} "/usr/local/bin/md5 /opt/dba/scp/$bname" | awk '{print $4}') 
        echo "comparing ${hash} to ${t}" >&2
        [ "${hash}" = "${t}" ] || echo "Files are not Identical!!!"
    done 
done < /home/izivanov/iz3

When in doubt, print everything. Smilie
# 30  
Old 03-08-2011
Okay we got something!

HTML Code:
(root):/home/izivanov# sh dirsync5.sh
trying /opt/dba/scp/xxxxxxxxx (xxxxxxxxc)
local hash is xxxxxxxxxxxxxxxxxx
ssh-ing to box box2
comparing xxxxxxxxxxxxxxxxxxxxx to xxxxxxxxxxxxxxxxxxxxxxxx
~
~
~
~
Question why is it only ssh-ing into box 2?

Last edited by zixzix01; 03-09-2011 at 06:00 PM..
# 31  
Old 03-08-2011
Check what /usr/local/bin/hosts prints. That loop won't break until read fails for some reason. Try running /usr/local/bin/hosts by itself and see what it does.

You can't md5sum things like /etc/sudoers without root access. And automatic passwordless remote root access to every machine is scary, so maybe you don't want to check that one... That weird 'opened' must be part of an error message -- odd place for it to end up, I'd have expected them to go to stderr!

But we're getting there. It's definitely able to verify some files now.
This User Gave Thanks to Corona688 For This Post:
# 32  
Old 03-09-2011
Btw I am running with root access. I didn't need to provide my login info to ssh with the script before to do this check either.

Its executable from anywhere with just "hosts" line. If I run it from Box 1 from which we make all our changes from, I get a list of all the boxes:

box 1(root):/home/izivanov# hosts
box 2
box 3
box4
~
~
~
box n
And if I run it from box 2, I'll get:

box 1
box3
box4
~
~
~
Box n

Do you understand?


So running the script from box 1, its getting only the first line of `hosts`, i.e. Box 2, and then not checking the file in question against that box either!

We also include `hostname' executable so that it would do this check on every box including the one I'm currently on, box 1! But it's not doing that!

Last edited by zixzix01; 03-09-2011 at 10:42 AM.. Reason: Forgot to add something!
# 33  
Old 03-09-2011
I really don't understand why it's not looping through all hosts... When loops break down like that, simplify it until you get something that works as expected and build from there.
Code:
while read fname; do 
    bname=$(basename $fname) 
    echo "trying "${fname} (${bname})" >&2

    hash=$(/usr/local/bin/md5 /opt/dba/scp/$bname | awk '{print $4}')

    echo "local hash is ${hash}"

    # should just print the entire list of hosts repeatedly
    /usr/local/bin/hosts

done < /home/izivanov/iz3

# 34  
Old 03-09-2011
Yup its exactly what happened!

It displayed the local hash, and then listed all of the servers. However I don't even need the see the hash. I just need to display on which server the hash doesn't correspond to the original file hash!

---------- Post updated at 12:35 PM ---------- Previous update was at 12:32 PM ----------

Sorry here is the output also:

(root):/home/izivanov# sh dirsync6.sh
trying /opt/dba/scp/xxxxxxxxxxx (xxxxxxx)
local hash is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Box 2
box 3
~~~
etc

and then it repeats for all the files the same!

Last edited by zixzix01; 03-09-2011 at 06:00 PM..
# 35  
Old 03-09-2011
building from there:
Code:
while read fname; do 
    bname=$(basename $fname) 
    echo "trying "${fname} (${bname})" >&2

    hash=$(/usr/local/bin/md5 /opt/dba/scp/$bname | awk '{print $4}')

    echo "local hash is ${hash}"

    # should just print the md5's
    /usr/local/bin/hosts | while read box
    do
        # should print md5's repeatedly
        ssh ${box} "/usr/local/bin/md5" "/opt/dba/scp/$bname"
    done

done < /home/izivanov/iz3

---------- Post updated at 11:45 AM ---------- Previous update was at 11:41 AM ----------

...and if that works
Code:
while read fname; do 
    bname=$(basename $fname) 
    echo "trying "${fname} (${bname})" >&2

    hash=$(/usr/local/bin/md5 /opt/dba/scp/$bname | awk '{print $4}')

    echo "local hash is ${hash}"

    # should just print the md5's
    /usr/local/bin/hosts | while read box
    do
        # should print md5's repeatedly
        T=$(ssh ${box} "/usr/local/bin/md5" "/opt/dba/scp/$bname" | awk '{ print $4;}')
        [ "$T" = "$hash" ] || echo "${box} bname differs!"
    done

done < /home/izivanov/iz3

I just realized something. Not all the files you want to test are under /opt/dba/scp, are they? Not if you want to check /etc/sudoers!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

2. Shell Programming and Scripting

Create simple script

Dear all, I have a directory named A and some subdirectories named B, C, D with .xml files. I want to use the following command to strip the file. sed -re ':start s/<*>//g; /</ {N; b start}' file.xml > file.xml At the same time, I want to remove the blank lines using sed '/^$/d' How can... (6 Replies)
Discussion started by: corfuitl
6 Replies

3. Shell Programming and Scripting

How to create a simple copy script?

Guys I want to do this: copy: /var/router/system1/config/backup/install.put /var/router/system2/config/backup/install.put /var/router/system3/config/backup/install.put /var/router/system4/config/backup/install.put into: /var/router/system1/config/install.dat... (22 Replies)
Discussion started by: DallasT
22 Replies

4. Shell Programming and Scripting

Create md5 sums and archive the resulting md5 files

Hello everyone, I am looking to basically creating md5sum files for all iso files in a directory and archive the resulting md5 files into a single archive in that very same directory. I worked out a clumsy solution such as: #find files for which md5sum are to be created and store the... (1 Reply)
Discussion started by: SurfTranquille
1 Replies

5. Shell Programming and Scripting

How to create a simple shell script to backup

Hello - I am in process of deleting many files which are older than 4 weeks. For example I am inside: /subsystem/prod/ Files are with various extentions, but anything older than 4 weeks should be deleted. What would be the most simplest script to acheive this? (4 Replies)
Discussion started by: DallasT
4 Replies

6. Solaris

How to create a simple background script on Solaris

I have a local account for a unix server. The idle timeout for the account is around 10 mins. I have to login to the server multiple times during the day. Is there a way to increase the idle timeout or may be a script that I can run on background so it is not idle. Something like echo date every 9... (3 Replies)
Discussion started by: vinaysa
3 Replies

7. Shell Programming and Scripting

Simple SSH script

I have several unix servers, I need to logon to each server and find out if an id exists on that server. I need a simple script for this, i have come up with the following script, but I cannot bring the output of a child process on the remote server. for i in `cat SERVER_LIST` do ssh $i... (5 Replies)
Discussion started by: ramky79
5 Replies

8. Shell Programming and Scripting

Simple Script to create folders

Hi I want to write a small script that will create folders named from `AAAA' all the way to `ZZZZ'. That is: `AAAA' `AAAB' `AAAC' ... `AABA' `AABB' `AABC' ... `ABAA' `ABAB' `ABAC' ... `ABBA' ... `ZZZZ' (4 Replies)
Discussion started by: ksk
4 Replies

9. Shell Programming and Scripting

Modifying simple commands to create a script

Can anyone direct me to a resource that explains scripting in simple terms? I have visited many sites and browsed this forum and have yet to find simple explanations. (8 Replies)
Discussion started by: rocinante
8 Replies

10. Shell Programming and Scripting

How to create md5 Hash variable?

I have a script that runs the grub-md5-crypt command based on whether the pass_value variable is a non-zero string. The md5 hash is being created in the /opt/hostconfigs/$HOST file, but I can't echo $md5_value. It is blank. Is there a way to create and echo a md5 hash variable? if then... (1 Reply)
Discussion started by: cstovall
1 Replies
Login or Register to Ask a Question