Compare output rather than command

前端 未结 3 1100
鱼传尺愫
鱼传尺愫 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:14

    [ isn't bash syntax, it is a command. So you must have a space between it and its first argument $LOCALMD5. There also needs to be a space between $REMOTEMD5 and ].

    0 讨论(0)
  • 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!

    0 讨论(0)
  • 2020-12-06 06:29

    Try;

    if [ "$LOCALMD5" == "$REMOTEMD5" ]
    

    which should work better.

    Edit: I think you got == and != reversed in your code.

    0 讨论(0)
提交回复
热议问题