The principle shell code is as follows:
#!/bin/shcat ../androidsrc | while read linedo ip=$(echo $line | awk ‘{print $1}‘) srcdir=$(echo $line | awk ‘{print $2}‘) destdir=$(echo $line | awk ‘{print $3}‘) user=$(echo $line | awk ‘{print $4}‘) port=$(echo $line | awk ‘{print $5}‘) build=$(echo $line | awk ‘{print $6}‘) echo $ip" "$srcdir" "$destdir" "$user" "$port" "$build #rsync -av $srcdir "-e ssh -p $port" [email protected]$ip:$destdir ssh -p $port [email protected]$ip sh $builddone
The androidsrc file is as follows:
xxx.yyy.zzz.zzz /data/build/xgame2/src/ /data/build/xgame/src/ sggame 61693 /data/build/buildgame.shxxx.yyy.zzz.zzz /data/build/xgame2/src/ /data/build/xgame-ios/src/ sggame 61693 /data/build/buildgame2.shxxx.yyy.zzz.zzz /data/build/xgame2/src/ /data/build/xgame/src/ sggame 61693 /data/build/buildgame.shxxx.yyy.zzz.zzz /data/build/xgame2/src/ /data/build/xgame2/src/ sggame 61693 /data/build/buildgame2.shxxx.yyy.zzz.zzz /data/build/xgame2/src/ /data/build/xgame/src/ sggame 61693 /data/build/buildgame.shxxx.yyy.zzz.zzz /data/build/xgame2/src/ /data/build/xgame/src/ sggame 61693 /data/build/buildgame.shxxx.yyy.zzz.zzz /data/build/xgame2/src/ /data/build/xgame/src/ sggame 61693 /data/build/buildgame.shxxx.yyy.zzz.zzz /data/build/xgame2/src/ /data/build/xgame/src/ sggame 61693 /data/build/buildgame.shxxx.yyy.zzz.zzz /data/build/xgame2/src/ /data/build/xgame/src/ sggame 61693 /data/build/buildgame.shxxx.yyy.zzz.zzz /data/build/xgame2/src/ /data/build/xgame/src/ root 22 /data/build/buildgame.sh
Xxx. yyy. Zzz. Zzz indicates the IP address.
Problem Source: After executing this script, it is found that the loop is interrupted after only the first execution.
Problem resolution: After query, we found that the contents of the androidsrc file that has been in the pipeline or redirected were eaten in advance by SSH-p $ port [email protected] $ IP sh $ build.
The final modification is as follows:
#!/bin/shcat ../androidsrc | while read linedo ip=$(echo $line | awk ‘{print $1}‘) srcdir=$(echo $line | awk ‘{print $2}‘) destdir=$(echo $line | awk ‘{print $3}‘) user=$(echo $line | awk ‘{print $4}‘) port=$(echo $line | awk ‘{print $5}‘) build=$(echo $line | awk ‘{print $6}‘) echo $ip" "$srcdir" "$destdir" "$user" "$port" "$build #rsync -av $srcdir "-e ssh -p $port" [email protected]$ip:$destdir ssh -p $port [email protected]$ip sh $build < /dev/nulldone
Conclusion: During the while read operation, this issue should be taken into account if the standard input commands such as CAT, mail, ssh, grep, sed, and awk are processed. Otherwise, shell writing is a pitfall.
This article is from the "Technology for the Future" blog and is not reposted!