目录
ant的使用,命令!
参考文献:
ant+maven一键打包springboot上传服务器发布
shell脚本“syntax error:unexpected end of file”解决方案
Ant 引用配置文件
<!-- set global properties for this build -->
<property file="build.properties"/>
<!--输出配置信息-->
<target name="show_property" description="show build.properties conf">
<echo> ================== build.properties ================ </echo>
<echo>PROJECT_NAME=${ant.project.name}</echo>
<echo>DEST_DIR=${DEST_DIR}</echo>
</target>
target条件控制
<target name="detect.file" >
<condition property="fileIsExists" >
<and>
<available file="c:/123.txt"/>
</and>
</condition>
</target>
<target name="echoDemo" if="fileIsExists" depends="detect.file">
<echo message="hello ant"/>
</target>
Ant-sshexec-执行远程服务器或本地脚本
需要先下载第三方依赖包jsch-0.1.46.jar到ant/lib目录
<sshexec
host="${host}"
username="${usr}"
password="${pwd}"
trust="true"
command="pwd;./test.sh"
outputproperty="output" # sh 的输出,可用 ${output} 获取
/>
scp命令上传文件
<scp todir="${USERNAME}:${PASSWORD}@${SERVER}:${DEST_DIR}" trust="true">
<fileset dir="${LOCAL_PATH}">
<exclude name="build.properties"/>
<exclude name="build.xml"/>
<exclude name=".idea/"/>
</fileset>
</scp>
判断远程文件是否存在
#判断文件是否存在
if [ -f "/data/filename" ];then
echo "文件存在"
else
echo "文件不存在"
fi
shell脚本传参
#!/bin/bash
echo "脚本$0"
echo "第一个参数$1"
echo "第二个参数$2"
# 命令行输入
$ ./test.sh 1 2
#shell中将会输出:
脚本./test.sh # $0获取到的是脚本路径以及脚本名
# 后面按顺序获取参数,当参数超过10个时(包括10个),需要使用${10},${11}....才能获取到参数
第一个参数1
第二个参数2
shell脚本添加执行权限
chmod是权限管理命令change the permissions mode of a file的缩写。。
u代表所有者,x代表执行权限。 + 表示增加权限。
chmod u+x file.sh # 就表示对当前目录下的file.sh文件的所有者增加可执行权限。
shell脚本“syntax error:unexpected end of file”解决方案
原因:该脚本在windows下编辑或者在windows打开保存过。
DOS下文件和Linux下文件格式差异问题导致的。
在 idea 中右下角可以选择 LF 为换行标识。
在 服务器可以使用vi修改文件格式,如下:
vi dos.txt
:set fileformat=unix
:wq
原文:https://www.cnblogs.com/jarvankuo/p/11954929.html