Compare output rather than command

前端 未结 3 1104
鱼传尺愫
鱼传尺愫 2020-12-06 05:57

Trying to create a script to read a remote file and check the md5 checksum and alert if a mismatch yet getting an error I can\'t understand.

#!/bin/sh
REMOTE         


        
3条回答
  •  鱼传尺愫
    2020-12-06 06:25

    I think it should be like this:

    #!/bin/sh
    REMOTEMD5=$(ssh user@host 'md5sum file.txt')
    LOCALMD5=$(md5sum 'file.txt')
    if [ "$LOCALMD5" == "$REMOTEMD5" ]
    then
      echo "all OK"
    else
      echo -e "no match, Local:"$LOCALMD5"\nRemote:"$REMOTEMD5
    fi
    

    The space between the bracket and the value is important!

提交回复
热议问题