konradsadek
asked on
Unix Shell Script (looping through records)
I am new to Unix shell scripting and just need to create a simple script that compares the checksums of a directory to that of a directory on another computer, however, when assigning variables to the system call I get errors, here is my code:
#!/bin/bash
FILES="*"
for f in "$FILES"
do
a=cksum $f
b=rsh myUnixName -l myUserId cd /export/home/config; cksum $f
if [ $a != $b ]
then
echo "Attention - $f does not match"
fi
done
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wonderful - thanks!
FILES="*"
for f in "$FILES"
do
a=$(cksum $f)
b=$(rsh myUnixName -l myUserId "cd export/home/config; cksum $f")
if [ "$a" != "$b" ]
then
echo "Attention - $f does not match"
fi
done
- execute commands and assign the result to a variable with $( ) or ` `
- enclose remote commands in double quotes " " to protect metacharacters like the semicolon from being interpreted by the local shell
- compare the right variables
- use double quotes around string variables to protect possibly contained spaces
- use ssh wherever possible, rsh is considered insecure
wmp