ssh sftp自动部署expect

6 篇文章 0 订阅

git服务器上的搭建

参考:https://blog.csdn.net/V__KING__/article/details/103196242

开发pc ubuntu上自动部署脚本

作用:

  1. 将本地代码push到git服务器上(git服务器会自动编译)
  2. 将git服务器上的编译文件下载到local主机上
  3. 将local主机上的编辑文件通过sftp上传到arm板
#!/bin/sh
ip_arm=192.168.7.115
username_arm=root
password_arm=123456
path_arm_app=/webApp

src_file=$(git diff --name-status  HEAD~1|egrep "^(A|M)"| awk '{print $2}')

expect_scp_to_arm(){
	expect <<-EOF
	spawn scp -r $1 $username_arm@$ip_arm:$path_arm_app/$1
	expect {
		"*yes/no" { send "yes\n";exp_continue }
		"*password:" { send "$password_arm\n" }
	}
	expect eof
	EOF
}

expect_cp_to_arm(){
	dir_file=`dirname $1`
	echo $dir_file
	expect <<-EOF
	spawn sftp $username_arm@$ip_arm
	expect {
		"*yes/no" { send "yes\n";exp_continue }
		"*password:" { send "$password_arm\n" }
	}
	expect {
		"sftp>" {send "mkdir $path_arm_app/$dir_file\n"}
	}
	send "cd $path_arm_app/$dir_file\n"
	send "put -pr $1\n"
	send "quit\n"
	expect eof
	EOF
}

scp_fast_cache_to_local(){
	echo "======copy fast compiled *.mod to local cache dirctory"
	git_ip=192.168.7.74
	git_name=git
	git_repo_path=/home/git/webApplication/cache/*
	echo $git_name
	expect <<-EOF
	spawn scp -r -P 19066 $git_name@$git_ip:$git_repo_path cache
	expect {
		"*yes/no" { send "yes\n";exp_continue }
		"*password:" { send "1\n" }
	}
	expect eof
	EOF
}

scp_LocalCache_to_arm(){
	echo "======copy local cache to arm"
	expect <<-EOF
	spawn scp -r cache $username_arm@$ip_arm:$path_arm_app
	expect {
		"*yes/no" { send "yes\n";exp_continue }
		"*password:" { send "$password_arm\n" }
	}
	expect eof
	EOF
}

git_push_to_git_server(){
	echo "======git push to git server"
	expect <<-EOF
	spawn git push
	expect {
		"*password:" { send "1\n" }
	}
	expect eof
	EOF
}

# main
if [[ $1 == "upload" ]]; then
	echo "upload to arm ..."
	for file in $src_file; do
		# expect_scp_to_arm $file
		expect_cp_to_arm $file
	done
	git_push_to_git_server
	scp_fast_cache_to_local
	scp_LocalCache_to_arm
elif [[ $1 == "arm" ]]; then
mvc run
else
mvc clean
mvc compile
mvc run
fi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值