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...
# 22  
Old 03-08-2011
I used the suggestion from Chubler. Namely:

Code:
#!/usr/bin/sh 
 
while read fname; do 
    bname=$(basename $fname) 
    first=0 
    {
      hostname
      /usr/local/bin/hosts
    } | while read box; do 
        t=$(ssh ${box} "/usr/local/bin/md5 /opt/dba/scp/$bname" | awk '{print $4}') 
        if [ $first -eq 0 ]; then 
            hash=$t
            first=1 
        else 
            [ "${hash}" == "${t}" ] || echo Files are not Identical!!!
        fi 
 
    done 
done < /home/izivanov/iz3

# 23  
Old 03-08-2011
You said you incorporated it, not copied it letter-for-letter...

Could you put echo statements inside the loops to see where it's hanging?
Code:
#!/usr/bin/sh 
 
while read fname; do 
    bname=$(basename $fname) 
    echo "trying "${fname} (${bname})" >&2
    first=0 
    {
      echo "running hostname" >&2
      hostname
      echo "finished running hostname, now running /usr/local/bin/hosts" >&2
      /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}') 
        if [ $first -eq 0 ]; then 
            hash=$t
            first=1 
        else 
            [ "${hash}" = "${t}" ] || echo "Files are not Identical!!!"
        fi 
 
    done 
done < /home/izivanov/iz3

Also fixed some might-have-been-syntax errors, highlighted in red. Not all shells know what == means, but = should go. And you shouldn't have loose !'s hanging around unquoted, in some shells ! is a history command.
# 24  
Old 03-08-2011
Code:
[ "${hash}" = "${t}" ] || echo "Files are not Identical!!!"

Shouldn't it be "!=" where the "=" is? I want to have the echo statement say that when the files are not the same, right?

Thank you!

---------- Post updated at 12:21 PM ---------- Previous update was at 12:02 PM ----------

It says:

Syntax error on line 5 : '(' is not expected!
# 25  
Old 03-08-2011
Quote:
Originally Posted by zixzix01
Code:
[ "${hash}" = "${t}" ] || echo "Files are not Identical!!!"

Shouldn't it be "!=" where the "=" is? I want to have the echo statement say that when the files are not the same, right?
this || that means "run this, and if it fails, run that". So if it's not equal, it runs echo ...
The && syntax is the opposite: run this, if it succeeds, run that.

It's very handy for chaining a number of dependent commands in a row without needing n+1 levels of nested if. a && b && c && d && e will stop at b if b fails.
Quote:
It says:

Syntax error on line 5 : '(' is not expected!
My bad, I put an extra quotation mark in that. Substitute this line:
Code:
echo "trying ${fname} (${bname})" >&2

# 26  
Old 03-08-2011
Wow okay here we go finally:

(root):/home/izivanov# sh dirsync3.sh
trying /opt/dba/scp/xxxxxxxx (xxxxxxxxxxxc)
running hostname
ssh-ing to box xxxxxxx
finished running hostname, now running /usr/local/bin/hosts
trying /opt/dba/scp/xxxxxxxxx (xxxxxxxxxx)
running hostname
ssh-ing to box xxxxxxxx
finished running hostname, now running /usr/local/bin/hosts
trying /opt/dba/scp/xxxxxxxxxxx (xxxxxxx)
running hostname
ssh-ing to box xxxxxx
finished running hostname, now running /usr/local/bin/hosts
trying /opt/dba/scp/xxxxxxxxxx (xxxxxxxxxxxx)
running hostname
ssh-ing to box xxxxxx
finished running hostname, now running /usr/local/bin/hosts
trying /etc/sudoers (sudoers)
running hostname
ssh-ing to box xxxxxxx
finished running hostname, now running /usr/local/bin/hosts
trying /opt/dba/binxxxxxxxxxx (xxxxxxxxxxxx)
running hostname
ssh-ing to box xxxxxxx
finished running hostname, now running /usr/local/bin/hosts


At least that's output! Confused on the output. It doesn't give me much useful info about which box these files are not identical to the original box...

---------- Post updated at 02:31 PM ---------- Previous update was at 02:25 PM ----------

Looks like its just running the hosts and hostname and not recognizing them as executables!

---------- Post updated at 02:33 PM ---------- Previous update was at 02:31 PM ----------

Somehow its supposed to run the MD5 on the file against the "hosts" file and also "hostname" which is the current box name from which I'm running this script!

Last edited by zixzix01; 03-09-2011 at 05:59 PM..
# 27  
Old 03-08-2011
You were running these files as executables before -- maybe accidentally, but that had me assuming they were scripts. Are they actually just text files?
# 28  
Old 03-08-2011
Sorry here is the hosts file:

Code:
cat <<-EnD | egrep -vx "`/usr/bin/hostname`"
box 1
box 2
~
~
~
box n
EnD

And the hostname is just an executable that brings up the hostname of the server I am on currently! Host is also an executable file!

Last edited by zixzix01; 03-08-2011 at 04:28 PM.. Reason: addition of information
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