linux

1. 不存在就创建文件夹
if [ ! -d "ekhip/" ];then
    mkdir /opt/ekhip
else
    echo "/opt/ekhip exists"
fi

2. 看在文件中是否有某个字符串
grep "esbBnormal" esbBresult.txt
                if [ $? -eq 0 ] ; 
                    then
                        ##esb2 成功
                        sleep 3s
                        ##nginx normal reload
                        ssh root@192.168.18.143 /bin/bash /opt/nginxnormal.sh
                fi


3. 远程连接获取返回值直接追加到文件中
ssh root@$ip "cmd" >> ./log

4. 变量赋值对于echo的好像没有用?
result=`ssh x@B ~/command.sh`

5. 是否可以在远程ssh命令中使用变量?
http://cn.voidcc.com/question/p-pfaixobb-qy.html

6. 远程拷贝 远程连接
scp -r $PATH_EKHIP/esb root@192.168.18.144:/opt

7. 在过程中遇到远程启动restart.sh 无效 然后加了source /etc/profile 就好了
https://www.cnblogs.com/yjmyzz/p/ssh-remote-execute-shell.html


8. 配置免密传输
ssh-keygen -t rsa
cd ~/.ssh
cp -rf id_rsa.pub authorized_keys
##将秘钥文件拷贝到esb1
scp -r ~/.ssh/ root@192.168.18.143:/root/

9. 获取时间差
       start=`date +%s -d "$(date "+%Y-%m-%d %H:%M:%S")"`
end=`date +%s -d "$(date "+%Y-%m-%d %H:%M:%S")"`
diff=$(($end-$start))

10. 判断是否有info文件
            a="/opt/$(getEhkippath)/$1/log/ekhip_info.`date '+%Y-%m-%d'`.0.log"
            if [ -f $a ];then
                size=`ls -lrt $a | cut -d " " -f 5`
                if [ $size -gt 0 ];then 
                    grep "Started MyApplication" /opt/$(getEhkippath)/$1/log/ekhip_info.`date '+%Y-%m-%d'`.0.log
                    if [ $? -eq 0 ];then
                        res=0
                        info="`date '+%T'` ## $1模块启动完毕"
                        break
                    fi
                fi
            fi

11. while循环
   while [ $diff -le $timelimit ] ##小于等于
         do
             ...
     done

 

posted @ 2020-04-27 09:11  仓鼠爱画方格子  阅读(159)  评论(0编辑  收藏  举报