Thanks for that, and yet still I have questions, I apologize.
I think originally he had /usr/bin declared...I'm getting errors about "md5" function!
Here is what I have so far!
Code:
hosts=`cat /home/izivanov/iz_hosts` #where iz_hosts is a txt file list of all hosts/servers
for fname in /home/izivanov/iz2 #where iz2 is a file with all the files with pathnames
do
hash=$(md5 $fname | awk '{print $4}' )
bname=$(basename $fname)
for box in ${hosts}
do
t=$(ssh ${box} "md5 fname /opt/dba/scp/$bname")
test_hash=$(echo "$t" | awk '{print $4}')
if [ "hash" != "$test_hash"] ; then
echo Files Are Not Identical
fi
done
done
And this is what I get in return:
:/home/izivanov# sh dirsync.sh
sh: md5: not found.
dirsync.sh[10]: test: Specify a parameter with this command.
sh: md5: not found.
dirsync.sh[10]: test: Specify a parameter with this command.
sh: md5: not found.
dirsync.sh[10]: test: Specify a parameter with this command.
sh: md5: not found.
dirsync.sh[10]: test: Specify a parameter with this command.
sh: md5: not found.
dirsync.sh[10]: test: Specify a parameter with this command.
sh: md5: not found.
dirsync.sh[10]: test: Specify a parameter with this command.
sh: md5: not found.
dirsync.sh[10]: test: Specify a parameter with this command.
I think its not recognising my md5 command. BTW I am working in SecureCRT connecting to HP-UX servers. If I didn't already mention that!
Your second try, 'for fname in /home/izivanov/iz2' is even weirder, since for doesn't read files.
Both should be done as while read X ; do stuff ; done < filename
Code:
while read fname
do
hash=$(/usr/bin/md5 "${fname}" | awk '{print $4}' )
bname=$(basename $fname)
while read box
do
# what is 'md5 fname' supposed to do? is there really a file named 'fname' over there?
# t=$(ssh ${box} "/usr/bin/md5 fname /opt/dba/scp/$bname"| awk '{print $4}')
t=$(ssh ${box} "/usr/bin/md5 /opt/dba/scp/$bname"| awk '{print $4 }')
[ "${hash}" = "${t}" ] || echo Files Are Not Identical
done < /home/izivanov/iz_hosts
done < /home/izivanov/iz2
Depending on your shell there may be more efficient ways to get the fourth parameter than awk '{print $4}' but we don't know what your shell is yet.
Thank you. I'm , hence the very bad programming mistakes. I never programmed in my life. But now have to learn it!
fname is supposed to be a file name which is taken out of the file iz2 (the one in /home/izivanov/iz2)
The file just lists the 5 files to be changed with their path names like so:
HTML Code:
/opt/dba/scp/so-and-so
/opt/dba/scp/so-and-so2
/opt/dba/scp/so-and-so3
etc.
---------- Post updated at 05:13 PM ---------- Previous update was at 04:47 PM ----------
After putting this in my script i still get the same errors about MD5. Don't know what ails it!
My shell is:
:/home/izivanov# echo $SHELL
/sbin/sh
Don't know if that helps!
Here is the script:
Code:
(root):/home/izivanov# vi dirsync.sh
"dirsync.sh" 12 lines, 312 characters
while read fname
do
hash=$(/usr/bin/md5 ${fname} | awk '{print $4}' )
bname=$(basename $fname)
while read box
do
t=$(ssh ${box} "/usr/bin/md5 /opt/dba/scp/$bname" | awk '{print $4}')
[ "${hash}" = "${t}" ] || echo Files are not Identical!!!
done < /home/izivanov/iz_hosts
done < /home/izivanov/iz2
Here is the output!
(root):/home/izivanov# sh dirsync.sh
dirsync.sh[3]: /usr/bin/md5: not found.
sh: /usr/bin/md5: not found.
dirsync.sh[3]: /usr/bin/md5: not found.
sh: /usr/bin/md5: not found.
dirsync.sh[3]: /usr/bin/md5: not found.
sh: /usr/bin/md5: not found.
dirsync.sh[3]: /usr/bin/md5: not found.
sh: /usr/bin/md5: not found.
rtidsva(root):/home/izivanov#
/usr/local/bin/ is a weird place for it to be. That's not usually in your PATH, either. It might have been custom-built and installed on just that server... You'd better make sure all the servers in question actually have it.
If they do, there you go, /usr/local/bin/md5.
If they don't, hmm.... how big are these files you're checking?
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)