shell脚本后台执行
执行脚本本身是一个进程,然后每条命令至少一个进程。进程间的关系是父子关系,和在Shell提示符下运行是一样的。
‘贰’ shell脚本中tail -f 日志输出到文件, 如果shell脚本后台运行日志无法写入文件,该如何处理
如果找到关键字,停止tail,继续执行后面的,但如果没找到的情况你没讲,我这个是如果超时1分钟没找到,也停止tail,并且终止脚本继续执行。{ sed /"$keywords"/q; kill $!; } < <(exec timeout 1m tail -Fn 0 "$log_file")适合用在脚本中,$keywords 和 $log_file 是要查找的关键字和目标文件,替换掉或者脚本前面设置变量。这个命令用到了进程替换(bash相关),和遇到错误停止(凡是脚本都应该用),所以脚本开头得是这两行 #!/bin/bashset -euxo pipefail并且执行这个脚本也得用 bash xxxx.sh,虽然CentOS里 sh 是 bash 的软链,但也不能用 sh,得用 bash
‘叁’ 如何用Java后台执行SHELL脚本
通过Runtime.getRuntime().exec(String [] commands)来执行即可,比如
Runtime.getRuntime().exec("/usr/local/b.sh");
前提是你的shell脚本已经有执行权限,如没有,可以执行("sh /usr/local/b.sh")
‘肆’ shell 脚本中后台调用函数结束
比面shell脚本文件:#===========test.sh! /bin/shecho_line(){ echo date echo "Wellcome to shell func!"}echo_hello(){ echo "Hello World!"}#======================shell调用两函数啊我用【./test.sh echo_hello】却没输我已经给test.sh加执行权限
请问envsetup.sh边
function gettop()
{
local TOPFILE=build/core/envsetup.mk
if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
echo $TOP
else
if [ -f $TOPFILE ] ; then
# The following circumlocution (repeated below as well) ensures
# that we record the true directory name and not one that is
# faked up with symlink names.
PWD= /bin/pwd
fi
}并没返值
调用何获取参数 T=$(gettop)
实际参数谢谢
‘伍’ shell脚本执行问题
将表名写入文件,一行一个,通过循环就可以导出多个表的数据。
执行导出命令时后面加 & 放入后台执行,就可以同时执行多个命令。
tableList=file.txt
whilereadtable
do
#exportdatafrom$table&
done<$tableList
‘陆’ shell脚本后台执行命令后怎么知道该命令是否结束
那你可以在脚本中添加完成提示
你可以在你的shell脚本的最后加一句echo
echo "The script is finished"
‘柒’ 编写shell脚本让mysql开机自启并后台运行
1、RHEL或CentOS
chkconfig mysqld on 即可开机自启
2、windows服务里有mysql,也可设置开机启动