- 浏览: 40415 次
- 性别:
- 来自: 武汉
文章分类
- 全部博客 (52)
- hibernate (3)
- spring (1)
- struts (0)
- commons (0)
- 英语自我介绍 (1)
- sql (18)
- extjs (0)
- linux (4)
- java (7)
- svn (0)
- html-css (1)
- ant (1)
- weblogic (1)
- perl (2)
- jsp (2)
- jms (2)
- log4j (1)
- android (2)
- maven (1)
- memcached (1)
- webservice (1)
- 在eclipse中使用Lombok (1)
- js (2)
- 在win7上安装oracle 10g配置文件更改 (0)
- myeclipse10安装svn (1)
最新评论
#!/bin/ksh
#ident "%W%"
function sumRows {
cp $1 $1.tmp
num=`grep rows $1.tmp | awk '{print $2}'`
if [ -z "$num" ] ; then
num=0
fi
num=`echo "$num+$2" | bc`
grep -v rows $1.tmp > $1
echo rows $num >> $1
rm $1.tmp
}
function startMarxJob {
if [ "$isTrackStatus" != "true" ] ; then
return 0;
fi
while getopts j:p:c:m:d: args
do
case $args in
j) JOB_NAME="$OPTARG";;
p) PID="$OPTARG";;
c) COMMENT="$OPTARG";;
m) allowMultiExec="$OPTARG";;
d) date="$OPTARG";;
esac
done
SQL_CMD="sp_marx_job_start @jobname='$JOB_NAME', @pid=$PID, @jobdate=$date, @allowMultiExecution='${allowMultiExec}', @comment='$COMMENT' , @id_return=@jobid out"
echo exec $SQL_CMD
jobTmpFile=${GCDR_TMPDIR}/.$$.sql.result.tmp
$ISQL $SQL <<EOD > $jobTmpFile
declare @jobid int
exec $SQL_CMD
go
EOD
if [ $? != 0 ] ; then
echo failed to exec sp_marx_job_start;
return -1;
fi
jobid=`grep Job_ID $jobTmpFile | awk '{print $2}'`
rm $jobTmpFile
if [ -n "$jobid" ] ; then
echo Job_ID $jobid;
echo Job_ID $jobid > ${GCDR_TMPDIR}/.${PID}.status;
return 0;
else
echo failed to start job;
return 99;
fi
}
function endMarxJob {
if [ "$isTrackStatus" != "true" ] ; then
return 0;
fi
while getopts F:S:c:x: args
do
case $args in
F) FILE="$OPTARG";;
S) STATUS="$OPTARG";;
c) COMMENT="$OPTARG";;
x) EXIT_STATUS="$OPTARG";;
esac
done
if [ ! -f $FILE ] ; then
echo "$FILE" does not exists!;
return 1;
fi
#grep job id and row processed
JOB_ID=`grep Job_ID $FILE | awk '{print $2}'`
ROWS_NUM=`grep rows $FILE | awk '{print $2}'`
if [ -z $ROWS_NUM ] ; then
ROWS_NUM=0;
fi
if [ finish = "$STATUS" ] ; then
SQL_CMD="sp_marx_job_finish $JOB_ID, $EXIT_STATUS, $ROWS_NUM, '$COMMENT'";
else
SQL_CMD="sp_marx_job_error $JOB_ID, $EXIT_STATUS, $ROWS_NUM, '$COMMENT'";
fi
echo exec $SQL_CMD
jobTmpFile=${GCDR_TMPDIR}/.$$.sql.result.tmp
$ISQL $SQL <<EOD > $jobTmpFile
exec $SQL_CMD
go
EOD
if [ $? != 0 ] ; then
echo failed to end job due to DB error.;
return 1;
fi
hasError=`grep -i ERROR $jobTmpFile`
rm $jobTmpFile
if [ -z "$hasError" ] ; then
echo Job_ID $JOB_ID has been marked as $STATUS successfully.;
return 0;
else
echo Job_ID $JOB_ID has not been marked as $STATUS successfully due to $hasError;
return 1;
fi
}
function startMarxTask {
if [ "$isTrackStatus" != "true" ] ; then
return 0;
fi
while getopts n:t:c:d:F: args
do
case $args in
n) TASK_NAME="$OPTARG";;
t) TYPE="$OPTARG";;
c) COMMENT="$OPTARG";;
F) FILE="$OPTARG";;
esac
done
if [ ! -f $FILE ] ; then
echo job status file does not exist. ;
return 99;
fi
#grep job id and row processed
JOB_ID=`grep Job_ID $FILE | awk '{print $2}'`
SQL_CMD="sp_marx_task_start $JOB_ID, '$TASK_NAME', '$TYPE', '$COMMENT' , @taskid out"
echo $SQL_CMD
jobTmpFile=${GCDR_TMPDIR}/.$$.sql.result.tmp
$ISQL $SQL <<EOD > $jobTmpFile
declare @taskid int
exec $SQL_CMD
go
EOD
if [ $? != 0 ] ; then
echo failed to exec sp_marx_task_start due to DB error;
return 1;
fi
taskid=`grep Task_ID $jobTmpFile | awk '{print $2}'`
rm $jobTmpFile
if [ -n "$taskid" ] ; then
grep -v Task_ID $FILE > $FILE.tmp;
echo Task_ID $taskid >> $FILE.tmp;
rm $FILE;
mv $FILE.tmp $FILE;
return 0;
else
echo failed to get task ID;
return 99;
fi
}
function endMarxTask {
if [ "$isTrackStatus" != "true" ] ; then
return 0;
fi
while getopts x:s:f:c:r:S:F: args
do
case $args in
x) EXIT_STATUS="$OPTARG";;
s) SUCCESS_NUM="$OPTARG";;
f) FAILURE_NUM="$OPTARG";;
c) COMMENT="$OPTARG";;
r) PROCESS_NUM="$OPTARG";;
S) STATUS="$OPTARG";;
F) FILE="$OPTARG";;
esac
done
if [ ! -f $FILE ] ; then
echo job status file does not exist. ;
return 99;
fi
TASK_ID=`grep Task_ID $FILE | awk '{print $2}'`
if [ finish = "$STATUS" ] ; then
SQL_CMD="sp_marx_task_finish $TASK_ID , $EXIT_STATUS , $SUCCESS_NUM , $FAILURE_NUM , '$COMMENT' , @taskid out";
else
SQL_CMD="sp_marx_task_error $TASK_ID , $EXIT_STATUS , $SUCCESS_NUM , $FAILURE_NUM , '$COMMENT' , @taskid out";
fi
echo $SQL_CMD
jobTmpFile=${GCDR_TMPDIR}/.$$.sql.result.tmp
$ISQL $SQL <<EOD > $jobTmpFile
declare @taskid varchar(80)
exec $SQL_CMD
go
EOD
if [ $? != 0 ] ; then
echo failed to end task due to DB error;
return 1;
fi
hasError=`grep -i ERROR $jobTmpFile`
rm $jobTmpFile
if [ -z "$hasError" ] ; then
#add the rows num
sumRows $FILE $PROCESS_NUM;
echo TASK_ID $TASK_ID has been marked as $STATUS successfully.;
echo $PROCESS_NUM rows been processed.;
return 0;
else
echo TASK_ID $TASK_ID has not been marked as $STATUS successfully due to $hasError;
return 1;
fi
}
function insertLogName {
if [ "$isTrackStatus" != "true" ] ; then
return 0;
fi
while getopts l:F: args
do
case $args in
l) LOGNAME="$OPTARG";;
F) FILE="$OPTARG";;
esac
done
if [ ! -f $FILE ] ; then
echo job status file does not exist. ;
return 99;
fi
JOB_ID=`grep Job_ID $FILE | awk '{print $2}'`
SQL_CMD="insert into marx_job_log values ( $JOB_ID , '${LOGNAME}' )"
echo $SQL_CMD
jobTmpFile=${GCDR_TMPDIR}/sql.result.tmp
$ISQL $SQL <<EOD > $jobTmpFile
declare @taskid varchar(80)
$SQL_CMD
go
EOD
if [ $? != 0 ] ; then
echo failed to record $LOGNAME to JOB_ID $JOB_ID;
return 1;
fi
hasError=`grep -i ERROR $jobTmpFile`
rm $jobTmpFile
if [ -z "$hasError" ] ; then
echo record $LOGNAME to JOB_ID $JOB_ID successfully.;
return 0;
else
echo failed to record $LOGNAME to JOB_ID $JOB_ID due to $hasError;
return 1;
fi
}
function insertMarxJob {
if [ "$isTrackStatus" != "true" ] ; then
return 0;
fi
PROCESS_NUM=0
COMMENT=""
while getopts j:p:x:r:S:c:d:l: args
do
case $args in
j) JOB_NAME="$OPTARG";;
p) PID="$OPTARG";;
x) exit_status="$OPTARG";;
r) PROCESS_NUM="$OPTARG";;
S) status="$OPTARG";;
c) COMMENT="$OPTARG";;
d) date="$OPTARG";;
l) logname="$OPTARG";;
esac
done
SQL_CMD="insert into marx_job_status values ('$JOB_NAME', $PID, $date, getdate(), getdate(),$exit_status, $status,$PROCESS_NUM,'$COMMENT')"
echo $SQL_CMD
jobTmpFile=${GCDR_TMPDIR}/.$$.sql.result.tmp
$ISQL $SQL <<EOD > $jobTmpFile
$SQL_CMD
print "Job_ID %1! starts", @@identity
go
EOD
if [ $? != 0 ] ; then
echo failed to insert job;
return -1;
fi
if [ $logname = "" ] ; then return 0 ; fi
jobid=`grep Job_ID $jobTmpFile | awk '{print $2}'`
rm $jobTmpFile
if [ -n "$jobid" ] ; then
SQL_CMD_LOG="insert into marx_job_log values ($jobid, '$logname')"
echo $SQL_CMD_LOG
$ISQL $SQL <<EOD
$SQL_CMD_LOG
go
EOD
fi
}
#ident "%W%"
function sumRows {
cp $1 $1.tmp
num=`grep rows $1.tmp | awk '{print $2}'`
if [ -z "$num" ] ; then
num=0
fi
num=`echo "$num+$2" | bc`
grep -v rows $1.tmp > $1
echo rows $num >> $1
rm $1.tmp
}
function startMarxJob {
if [ "$isTrackStatus" != "true" ] ; then
return 0;
fi
while getopts j:p:c:m:d: args
do
case $args in
j) JOB_NAME="$OPTARG";;
p) PID="$OPTARG";;
c) COMMENT="$OPTARG";;
m) allowMultiExec="$OPTARG";;
d) date="$OPTARG";;
esac
done
SQL_CMD="sp_marx_job_start @jobname='$JOB_NAME', @pid=$PID, @jobdate=$date, @allowMultiExecution='${allowMultiExec}', @comment='$COMMENT' , @id_return=@jobid out"
echo exec $SQL_CMD
jobTmpFile=${GCDR_TMPDIR}/.$$.sql.result.tmp
$ISQL $SQL <<EOD > $jobTmpFile
declare @jobid int
exec $SQL_CMD
go
EOD
if [ $? != 0 ] ; then
echo failed to exec sp_marx_job_start;
return -1;
fi
jobid=`grep Job_ID $jobTmpFile | awk '{print $2}'`
rm $jobTmpFile
if [ -n "$jobid" ] ; then
echo Job_ID $jobid;
echo Job_ID $jobid > ${GCDR_TMPDIR}/.${PID}.status;
return 0;
else
echo failed to start job;
return 99;
fi
}
function endMarxJob {
if [ "$isTrackStatus" != "true" ] ; then
return 0;
fi
while getopts F:S:c:x: args
do
case $args in
F) FILE="$OPTARG";;
S) STATUS="$OPTARG";;
c) COMMENT="$OPTARG";;
x) EXIT_STATUS="$OPTARG";;
esac
done
if [ ! -f $FILE ] ; then
echo "$FILE" does not exists!;
return 1;
fi
#grep job id and row processed
JOB_ID=`grep Job_ID $FILE | awk '{print $2}'`
ROWS_NUM=`grep rows $FILE | awk '{print $2}'`
if [ -z $ROWS_NUM ] ; then
ROWS_NUM=0;
fi
if [ finish = "$STATUS" ] ; then
SQL_CMD="sp_marx_job_finish $JOB_ID, $EXIT_STATUS, $ROWS_NUM, '$COMMENT'";
else
SQL_CMD="sp_marx_job_error $JOB_ID, $EXIT_STATUS, $ROWS_NUM, '$COMMENT'";
fi
echo exec $SQL_CMD
jobTmpFile=${GCDR_TMPDIR}/.$$.sql.result.tmp
$ISQL $SQL <<EOD > $jobTmpFile
exec $SQL_CMD
go
EOD
if [ $? != 0 ] ; then
echo failed to end job due to DB error.;
return 1;
fi
hasError=`grep -i ERROR $jobTmpFile`
rm $jobTmpFile
if [ -z "$hasError" ] ; then
echo Job_ID $JOB_ID has been marked as $STATUS successfully.;
return 0;
else
echo Job_ID $JOB_ID has not been marked as $STATUS successfully due to $hasError;
return 1;
fi
}
function startMarxTask {
if [ "$isTrackStatus" != "true" ] ; then
return 0;
fi
while getopts n:t:c:d:F: args
do
case $args in
n) TASK_NAME="$OPTARG";;
t) TYPE="$OPTARG";;
c) COMMENT="$OPTARG";;
F) FILE="$OPTARG";;
esac
done
if [ ! -f $FILE ] ; then
echo job status file does not exist. ;
return 99;
fi
#grep job id and row processed
JOB_ID=`grep Job_ID $FILE | awk '{print $2}'`
SQL_CMD="sp_marx_task_start $JOB_ID, '$TASK_NAME', '$TYPE', '$COMMENT' , @taskid out"
echo $SQL_CMD
jobTmpFile=${GCDR_TMPDIR}/.$$.sql.result.tmp
$ISQL $SQL <<EOD > $jobTmpFile
declare @taskid int
exec $SQL_CMD
go
EOD
if [ $? != 0 ] ; then
echo failed to exec sp_marx_task_start due to DB error;
return 1;
fi
taskid=`grep Task_ID $jobTmpFile | awk '{print $2}'`
rm $jobTmpFile
if [ -n "$taskid" ] ; then
grep -v Task_ID $FILE > $FILE.tmp;
echo Task_ID $taskid >> $FILE.tmp;
rm $FILE;
mv $FILE.tmp $FILE;
return 0;
else
echo failed to get task ID;
return 99;
fi
}
function endMarxTask {
if [ "$isTrackStatus" != "true" ] ; then
return 0;
fi
while getopts x:s:f:c:r:S:F: args
do
case $args in
x) EXIT_STATUS="$OPTARG";;
s) SUCCESS_NUM="$OPTARG";;
f) FAILURE_NUM="$OPTARG";;
c) COMMENT="$OPTARG";;
r) PROCESS_NUM="$OPTARG";;
S) STATUS="$OPTARG";;
F) FILE="$OPTARG";;
esac
done
if [ ! -f $FILE ] ; then
echo job status file does not exist. ;
return 99;
fi
TASK_ID=`grep Task_ID $FILE | awk '{print $2}'`
if [ finish = "$STATUS" ] ; then
SQL_CMD="sp_marx_task_finish $TASK_ID , $EXIT_STATUS , $SUCCESS_NUM , $FAILURE_NUM , '$COMMENT' , @taskid out";
else
SQL_CMD="sp_marx_task_error $TASK_ID , $EXIT_STATUS , $SUCCESS_NUM , $FAILURE_NUM , '$COMMENT' , @taskid out";
fi
echo $SQL_CMD
jobTmpFile=${GCDR_TMPDIR}/.$$.sql.result.tmp
$ISQL $SQL <<EOD > $jobTmpFile
declare @taskid varchar(80)
exec $SQL_CMD
go
EOD
if [ $? != 0 ] ; then
echo failed to end task due to DB error;
return 1;
fi
hasError=`grep -i ERROR $jobTmpFile`
rm $jobTmpFile
if [ -z "$hasError" ] ; then
#add the rows num
sumRows $FILE $PROCESS_NUM;
echo TASK_ID $TASK_ID has been marked as $STATUS successfully.;
echo $PROCESS_NUM rows been processed.;
return 0;
else
echo TASK_ID $TASK_ID has not been marked as $STATUS successfully due to $hasError;
return 1;
fi
}
function insertLogName {
if [ "$isTrackStatus" != "true" ] ; then
return 0;
fi
while getopts l:F: args
do
case $args in
l) LOGNAME="$OPTARG";;
F) FILE="$OPTARG";;
esac
done
if [ ! -f $FILE ] ; then
echo job status file does not exist. ;
return 99;
fi
JOB_ID=`grep Job_ID $FILE | awk '{print $2}'`
SQL_CMD="insert into marx_job_log values ( $JOB_ID , '${LOGNAME}' )"
echo $SQL_CMD
jobTmpFile=${GCDR_TMPDIR}/sql.result.tmp
$ISQL $SQL <<EOD > $jobTmpFile
declare @taskid varchar(80)
$SQL_CMD
go
EOD
if [ $? != 0 ] ; then
echo failed to record $LOGNAME to JOB_ID $JOB_ID;
return 1;
fi
hasError=`grep -i ERROR $jobTmpFile`
rm $jobTmpFile
if [ -z "$hasError" ] ; then
echo record $LOGNAME to JOB_ID $JOB_ID successfully.;
return 0;
else
echo failed to record $LOGNAME to JOB_ID $JOB_ID due to $hasError;
return 1;
fi
}
function insertMarxJob {
if [ "$isTrackStatus" != "true" ] ; then
return 0;
fi
PROCESS_NUM=0
COMMENT=""
while getopts j:p:x:r:S:c:d:l: args
do
case $args in
j) JOB_NAME="$OPTARG";;
p) PID="$OPTARG";;
x) exit_status="$OPTARG";;
r) PROCESS_NUM="$OPTARG";;
S) status="$OPTARG";;
c) COMMENT="$OPTARG";;
d) date="$OPTARG";;
l) logname="$OPTARG";;
esac
done
SQL_CMD="insert into marx_job_status values ('$JOB_NAME', $PID, $date, getdate(), getdate(),$exit_status, $status,$PROCESS_NUM,'$COMMENT')"
echo $SQL_CMD
jobTmpFile=${GCDR_TMPDIR}/.$$.sql.result.tmp
$ISQL $SQL <<EOD > $jobTmpFile
$SQL_CMD
print "Job_ID %1! starts", @@identity
go
EOD
if [ $? != 0 ] ; then
echo failed to insert job;
return -1;
fi
if [ $logname = "" ] ; then return 0 ; fi
jobid=`grep Job_ID $jobTmpFile | awk '{print $2}'`
rm $jobTmpFile
if [ -n "$jobid" ] ; then
SQL_CMD_LOG="insert into marx_job_log values ($jobid, '$logname')"
echo $SQL_CMD_LOG
$ISQL $SQL <<EOD
$SQL_CMD_LOG
go
EOD
fi
}
相关推荐
标题中的“一个批量域名解析的Shell脚本例子”是指通过Shell脚本来实现对大量域名进行DNS解析的功能。在IT行业中,这种操作常用于网络监控、安全分析或数据收集等场景。下面将详细介绍这个主题。 首先,`...
这里我们探讨几个基本的Shell脚本例子,包括用户交互、参数处理、文件解压缩以及进度条模拟。 1. 用户交互脚本: 在`show_var.sh`这个例子中,脚本通过`while`循环不断请求用户输入数字,直到用户输入"end"为止。`...
接下来,我们来看几个Shell脚本的例子: 1. **欢迎消息脚本**:这个脚本会在用户登录时显示一个欢迎消息。 ```bash #!/bin/bash echo "欢迎,$(whoami)!今天是$(date)。" ``` 这个脚本使用`whoami`命令获取...
Shell 脚本实例集锦 Shell 脚本是一种强大的工具,能够帮助程序员和系统管理员自动完成枯燥的工作,提高工作效率。以下是 23 个非常实用的 Shell 脚本实例,展示了 Shell 脚本编程的实用技术和常见工具用法。 一、...
一个简单的Shell脚本例子如下: ```bash #!/bin/bash echo "Mr.$USER, Today is:" echo "$(date '+%B%d%A')" echo "Wish you a lucky day!" ``` 这里,`#!/bin/bash`是Shebang,告诉系统使用哪个Shell解释器来执行...
以上这些例子涵盖了基本的Shell脚本操作,如变量使用、条件判断、流程控制、系统命令调用以及定时任务设置等。通过学习和实践这些脚本,可以深入了解Shell脚本编程,提升系统管理能力。对于Linux系统管理员、开发者...
通过阅读和实践"shell脚本大全"中的例子,你可以逐步掌握这些概念,并学会如何编写自己的脚本来提高工作效率。无论是在系统管理、自动化任务,还是在数据分析等领域,Shell脚本都发挥着重要的作用。记得实践是掌握...
在Linux环境下,shell脚本是自动化任务的强大工具,尤其对于数据导出这样的操作,通过编写shell脚本可以方便地实现定期备份或者按需导出。本文将深入讲解如何使用shell脚本来实现数据的导出,并结合Java代码进行调用...
每个例子都会详细介绍其功能、实现原理和使用方法,帮助读者掌握编写高效Shell脚本的技巧,提升在云计算环境中的操作能力。通过学习这些案例,无论是运维工程师还是Java开发者,都能更好地理解和运用Shell脚本,以...
Shell脚本是Linux系统中的一种强大工具,它允许用户通过编写简单的命令行指令组合来实现自动化任务。在《shell脚本100例(最新版).pdf》这本书中,作者详细介绍了各种实用的Shell脚本案例,涵盖了从基础语法到高级...
在Linux操作系统中,shell脚本是编写自动化任务和系统管理任务的常用工具。掌握在shell脚本中生成随机数的技巧对于IT专业人员来说是非常有用的。文章中提到的生成随机数的方法可以分为以下几点: 首先,可以使用...
在IT行业中,Shell脚本是一种强大的工具,尤其在Linux或Unix操作系统中,它允许用户自动化执行一系列命令,处理文件和目录,甚至进行复杂的任务管理。在这个特定的场景中,我们关注的是如何使用Shell脚本来生成`.txt...
本文将深入探讨“最简单shell脚本编程例子”中的核心概念,帮助新手快速掌握shell脚本的基础知识。 1. **Shell脚本简介**:Shell脚本是基于Bash或其他Shell环境(如sh、csh、ksh等)的文本文件,包含了可执行的命令...
在"shell脚本编写例子"这个主题中,我们将深入探讨如何编写和使用简单的shell脚本来提升日常操作效率。 首先,让我们了解什么是shell。Shell是操作系统提供的一种交互式界面,它接收用户输入的命令并执行。而shell...
shell脚本一个读写sd卡的案例,这个例子可以帮助出学者进步了解shell编程
本文档主要涉及了Linux Shell脚本的编写和使用,以下为详细知识点: 1. 基本Shell脚本结构:每个Shell脚本通常以#!bin/bash作为开头,这行代码被称为shebang行,告诉系统用哪个解释器来执行该脚本。接着是一些注释...
"shell脚本例子"则是指编写Shell脚本的实际示例,Shell脚本是用Bash或其他Shell解释器编写的程序,用于自动化一系列命令执行。例如,你可以编写一个脚本来备份特定的文件夹,或者自动检查系统的资源使用情况。学习...
Shell脚本编程是一种在Linux和Unix系统中广泛使用的编程方式,它允许用户通过编写脚本来自动化执行一系列系统命令。在本文中,我们将深入探讨几个关键的Shell脚本知识点,包括基本语法、变量、条件判断、循环、进程...
Shell脚本是Linux和Unix操作系统中的一个强大工具,它允许用户通过编写命令序列来自动化日常任务,从而提高工作效率。这份“Shell脚本学习指南”涵盖了从基础到高级的多个方面,帮助初学者和经验丰富的开发者深入...