开发者

error in getting a remote file in shell script

开发者 https://www.devze.com 2023-03-22 17:23 出处:网络
I have this script that is doing a scp onto 4 servers and getting the file on the calling server , but when I run it I get the following error:

I have this script that is doing a scp onto 4 servers and getting the file on the calling server , but when I run it I get the following error:

syntax error near unexpected token `then'
line 16: `if[[ $line = $texts ]] ; then 

The code is as follows:

#!/bin/sh
servers=("root@67.215.227.233" "root@57.245.127.134" "root@67.215.127.135" "root@116.244.128.153")
tlen=${#servers[@]}
count=o
total=0
texts="Untar done you can upload new .tar file"
for(( i=0; i<${tlen}; i++ ));
    do
    echo "in"
    scp ${servers[$i]}:/usr/site/html/test/test.txt /mnt/backups/updateimage
    ca开发者_JAVA技巧t test.txt ; while read line
    do
    echo "in"
    let count++
    echo "$line"
    if[[ $line = $texts ]] ; then 
    echo "true" 
    let total++ 
    else echo "false" 
    fi
   done < test.txt
done
exit 0


Put a space between if and [[

EDIT

I've just ran this test and it properly evaluates to false

#!/bin/bash

set -eu

texts="Untar done you can upload new .tar file"
line="foo"

if [[ $line = $texts ]] ; then
  echo "true"
else
  echo "false"
fi

I suspect your problem is elsewhere

0

精彩评论

暂无评论...
验证码 换一张
取 消