- 论坛徽章:
- 0
|
本帖最后由 下一秒 于 2010-07-20 12:01 编辑
公司安排一个测试任务,这个脚本我不懂哦。大侠帮忙给写一个详细的,最好有说明如何用。PERL一窍不通啊,帮忙啊
windows平台环境。
脚本1:模拟启动一个c:\WINDOWS\NOTEPAD.EXE
#!perl
BEGIN { require $ENV{'LKROOT'}.'/etc/default/LifeKeeper.pl'; }
use LK;
use POSIX;
use Getopt::Std; # use the standard getopt package
$LKROOT=$ENV{'LKROOT'};
$ResType="app";
$AppType="gen";
$CMD=`basename $0`;
chomp $CMD;
sub parseOptions { # noparams
getopts('t:i:');
$tag = "$opt_t";
$id = "$opt_i";
};
# Perform commands that restore the protected application to service.
# HINT: To fork a new process you can use the LifeKeeper supplied start command
# located at $LKROOT/bin/start.exe and executable in perl as illustrated here.
# For example, to start the Microsoft Notepad accessory as follows:
# system("start", "$ENV{'SystemRoot'}/notepad.exe", "$ENV{'LKROOT'}/TMP/YourFileName.txt");
# -------------------------------------------------------------------------------------
# Custom code goes here
# -------------------------------------------------------------------------------------
# RetCode is used to identify a successful or failed restore
$RetCode = $?>>8; # In perl, the application return code is offset 8 bits.
if ( $RetCode != 0 )
{
# Log failed restore and return failed.
`$ENV{'LKROOT'}/bin/lk_err -c FRS_ERR -n 27455 -d TO_STDERR -p $CMD "LifeKeeper: AppKit RESTORE; The \\"$tag\\" resource failed to start properly. Return code was \\"$RetCode\\". Restore has FAILED."`;
exit $RetCode;
}
# Return success
exit 0;
脚本2:停止NOTEPAD.EXE进程脚本
#!perl
BEGIN { require $ENV{'LKROOT'}.'/etc/default/LifeKeeper.pl'; }
use LK;
use POSIX;
use Getopt::Std; # use the standard getopt package
$LKROOT=$ENV{'LKROOT'};
$ResType="app";
$AppType="gen";
$CMD=`basename $0`;
chomp $CMD;
sub parseOptions { # noparams
getopts('t:i:');
$tag = "$opt_t";
$id = "$opt_i";
};
# Perform commands that remove the protected application from service.
# -------------------------------------------------------------------------------------
# Custom code goes here
# -------------------------------------------------------------------------------------
# RetCode is used to identify successful or failed remove
$RetCode = $?>>8; # In perl, the application return code is offset 8 bits.
if ( $RetCode != 0 )
{
# Log failed remove operation and return.
`$ENV{'LKROOT'}/bin/lk_err -c FRS_ERR -n 27855 -d TO_STDERR -p $CMD "LifeKeeper: AppKit REMOVE; The \\"$tag\\" resource failed to stop properly. Return code was \\"$RetCode\\". Remove has FAILED."`;
exit $RetCode;
}
# Return success.
exit 0; |
|