我的理解:<< EOF … EOF主要用在向外界命令发送批量内部执行语句,比如mysql,比如Oracle
mysql:
#!/bin/sh
mysql -uroot -p123456 <<EOF
use test;
select * from testaa while a=10000;
exit
EOF
Oracle
#!/bin/bash
#Filename:do.sh
su - oracle -c "
export ORACLE_SID=orcl
sqlplus /nolog << EOF
connect / as sysdba
startup;
exit;
EOF"
sleep 5
su - oracle -c
lsnrctl start
比如我这样做是向mysql发送了一次执行动作,节省xxx
$MYSQL db-monitor -u root << EOF
delete from process;
update application set run_status=0, ins_count=0;
select concat(application_name,':',server_port) comp from tbl_application order by id;
EOF
但是,这里面执行语句的输出能否在shell中读到
,我不知道!!!
。。。
一个注意点:
结尾的EOF在单独行写,
且前面不能有空格
,好像后面也不能有空格。习惯于左右缩进的,把<< EOF
写在函数里面或者循环里面的,要注意了。
是否组合命令前后比较
while ["一级循环"]; do
while ["2级循环"]; do
# 分别执行SQL
# sql1="INSERT INTO process ( pid, application_name,server_port,listen_port, xmx) VALUES "
# sql2="(${pid},'${app_name}',${server_port}, '${net_port:1}', '${Xmx}')"
#
# $MYSQL -uroot doorbell-monitor -e "${sql1} ${sql2}"
#
# $MYSQL -uroot db-monitor -e "update tbl_application set run_status=1, ins_count=ins_count+1 where application_name='$app_name' and server_port='$server_port'"
#
# 组合执行
$MYSQL db-monitor -u root << EOF
INSERT INTO process ( pid, application_name,server_port,listen_port, xmx)
VALUES (${pid},'${app_name}',${server_port}, '${net_port:1}', '${Xmx}');
update tbl_application set run_status=1, ins_count=ins_count+1 where application_name='$app_name' and server_port='$server_port';
#看这里!看这里!
EOF
log "29"
done
done