bash 指令碼總結

u013378306發表於2017-05-25

引數傳入:

$1代表第一個引數

./test.sh 1234  測試公司名

#!/bin/sh
companyId=$1
project_name=$2

echo "公司id:$companyId"


殺死程式

#lsof -i : $程式標識| sed -n '2,2p' |awk '{print $2}'|xargs kill -9 #
process_num=$(ps -ef|grep $程式標識|grep -v grep| sed -n '1,1p' |awk '{print $2}')
echo "$project_tag 程式號是: $process_num"


if else

if [ ! -n "$companyId" ]; then #判斷是否為空
  echo "!!!!!!!!!!!!!!!請填寫引數companyId"
  exit
fi

if [ ! -n "$process_num" ]; then  
  echo "port $project_tag not running!!!!!"  
else
  echo "$process_num....."
  kill -9 $process_num  
  echo "$project_name   $project_tag 已經被殺死..."
fi
sleep 1

遠端命令執行

scp -r $project_name-to.tar.gz root@192.168.1.111:/usr/local/project/$project_name/$project_name-from.tar.gz
ssh -p 22 root@192.168.1.111 << remotessh  
cd /usr/local/aigoes/$project_name
tar -zcvf $project_name.tar.gz  $project_name
echo "備份 $project_name 完成...."
tar -zxvf $project_name-from.tar.gz
cd /usr/local/project/
./restart.sh $companyId $project_name
exit
remotessh



相關文章