我有一个简单的文件传输bash脚本。当此脚本直接从solaris数据库服务器运行时,它将成功执行并将文件传输到远程服务器。但是当同一脚本运行一个Oracle作业时,它将失败,并显示以下错误消息。
我在all_scheduler_job_run_details表的输出列中找到此消息。
"Could not create directory '/home/user/.ssh'.
Host key verification failed.
Couldn't read packet: Connection reset by peer"
但是/home/user/.ssh已经存在,并且与远程服务器的密码连接较少。
v_local_dir=/u12/dw/temp
v_file_name=devcode_test_file
v_remote_dir=upload
v_usr=devcode
v_server=sftp1.umbrella.com
v_port=2222
v_cmd="cd ${v_remote_dir}
put ${v_local_dir}/${v_file_name}"
echo "Executing sftp command"
echo "Command is ${v_cmd}"
echo "${v_cmd}" | sftp -oPort=${v_port} ${v_usr}@${v_server}
Oracle创建程序代码
dbms_scheduler.create_program
(
program_name=>'USER.PROG_DEVCODE',
program_action=> '/u12/dw/sftp_to_remote.sh',
program_type=>'EXECUTABLE',
number_of_arguments=>1,
comments => 'push files',
enabled=>FALSE
) ;
dbms_scheduler.enable 'DW_USER_REPORT.PROG_PUSH_FILE_TO_DEVCODE');
Oracle创建作业程序
declare
p_job_name varchar2(500) := 'USER.JOB_PROG_DEVCODE';
p_command varchar2(500) := 'PROG_DEVCODE';
-- p_args := ''
p_type varchar2(500) := 'PROGRAM';
p_wait_result number := 1;
begin
DBMS_SCHEDULER.CREATE_JOB (
p_job_name -- IN VARCHAR2,
, p_command --program_name IN VARCHAR2,
, start_date => NULL
, repeat_interval =>
, end_date => NULL
, job_class => 'DEFAULT_JOB_CLASS'
, enabled => FALSE
, auto_drop => TRUE
, comments => NULL
, job_style => 'REGULAR'
);
DBMS_SCHEDULER.set_attribute(
p_job_name
, 'credential_name'
, 'USER.ORACLE_OS_CREDENTIAL'
);
DBMS_SCHEDULER.enable(
p_job_name
);
end;