文章目录
- 1. 脚本升级
- 2. 执行测试
- 3. 脚本关键词简述
- 补充案例
上一篇:
shell脚本触发java程序支持传参补跑 +crontab定时器_02
1. 脚本升级
cd /app/ly
#!/bin/bash
fdate=$(date +%Y%m%d%H%M%S)
flog='/app/ly/logs/shellrun-'
elog='/app/ly/logs/errors-'
fname=$flog$fdate'.log'
ename=$elog$fdate'.log'
nohup /app/jdk1.8.0_202/bin/java -cp "./ly.war/WEB-INF/classes" com.gblfy.shell.MainDeal $1 <<EOF > "$fname" 2>&1
EOF
if grep -i "Login failed" "$fname" > /dev/null
then
echo "ERROR: Login failed" >> "$ename"
fi
if grep -i "Not connected" "$fname" > /dev/null
then
echo "ERROR: Cannot connect to the destination" >> "$ename"
fi
if grep -i "No such file" "$fname" > /dev/null
then
echo "ERROR: Cannot change directory. No such file or directory." >> "$ename"
fi
if grep -i "No such directory" "$fname" > /dev/null
then
echo "ERROR: Cannot change remote directory. No such file or directory." >> "$ename"
fi
if grep -i "File or Directory does not exist" "$fname" > /dev/null
then
echo "ERROR: Cannot transfer. File or Directory does not exist" >> "$ename"
fi
2. 执行测试
不传参数
[root@localhost ly]# ./lyshell2.sh
[root@localhost ly]# cat logs/shellrun-20201227132209.log
没有接收到参数
开始获取当前日期:2020-12-27
[root@localhost ly]#
传参数
[root@localhost ly]# ./lyshell2.sh 2020-12-26
[root@localhost ly]# cat logs/shellrun-20201227132529.log
开始补跑: 2020-12-26这天的数据
[root@localhost ly]#
3. 脚本关键词简述
<< EOF
...
EOF
其中的"..."表示用户输入内容。
说明:EOF只是一个标示符,可以用其它非关键字符或字符串来代替,例如:
<< abc
.....
abc
补充案例
#!/bin/bash
#Filename:do.sh
su - oracle -c "
export ORACLE_SID=orcl
sqlplus /nolog <<EOF
connect / as sysdba
startup;
exit;
EOF"
sleep 5
su