Link to home
Start Free TrialLog in
Avatar of konradsadek
konradsadekFlag for United States of America

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

Open in new window

Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

#!/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

 - 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
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of konradsadek

ASKER

Wonderful - thanks!