原因:
现在代码用远程git管理,但是Linux服务器不能连接外网,只能曲线救国:在本地写代码,然后同步代码到Linux服务器,并发送指令进行编译。
准备工作:
安装expect:
我电脑上已经安装了brew,执行brew install expect
set user embest
set pass ******
set dir ~/Documents/share/application/d20
set appDir ~/Documents/share/application/d20/hs_door_temperature_cpp
set ip 192.168.100.200
set filen ../../hs_door_temperature_cpp
#拷贝源文件
spawn scp -r ${filen} ${user}@${ip}:${dir}
expect "${user}@${ip}'s password:"
send "${pass}\r"
interact
#修改权限
spawn ssh ${user}@${ip} "chmod 777 -R ${appDir}/*"
expect "${user}@${ip}'s password:"
send "${pass}\r"
interact
#编译
spawn ssh ${user}@${ip} "cd ${appDir}; ./auto.sh"
expect "${user}@${ip}'s password:"
send "${pass}\r"
interact
大功告成!
本文介绍了一种在无法直接访问外网的Linux服务器上,通过expect脚本实现从本地计算机同步代码并自动编译的方法。具体步骤包括使用scp命令复制文件,设置文件权限,以及远程执行编译脚本。
532

被折叠的 条评论
为什么被折叠?



