我正在尝试在没有ssh公钥的服务器的一定时间后在perl脚本中的scp命令期间退出密码输入提示。在这个脚本中,我使用后退标记将文件从一个服务器复制到另一个服务器,但脚本卡在密码提示符上,即使在指定的超时后也不会退出。
my $test = '';
my $exit_value = '';
eval {
my $timeout = 2;
local $SIG{ALRM} = sub { die "timeout\n" };
alarm($timeout);
$test = `scp foo.txt bar@baz:/`;
$exit_value = $? >> 8;
alarm(0);
}
if ($@) {
print "Time out";
}
有没有办法处理上述情况?
答案 0 :(得分:0)
从非交互式会话调用时,应设置BatchMode以完全禁用密码提示。
$test = `scp -o BatchMode=yes foo.txt bar@baz:/`;
见下文
BatchMode
If set to ``yes'', passphrase/password querying will be disabled.
This option is useful in scripts and other batch jobs where no
user is present to supply the password. The argument must be
``yes'' or ``no''. The default is ``no''.
答案 1 :(得分:0)
您还可以使用以下参数禁用host_key检查: -
$ test = scp -o BatchMode = yes -o StrictHostKeyChecking = no foo.txt bar @ baz:/;
答案 2 :(得分:0)
我使用Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
Buildfile: /home/jordi/NetBeansProjects/geneal/build.xml
-pre-init:
-init-private:
-init-user:
-init-project:
-init-macrodef-property:
-do-init:
-post-init:
-init-check:
-init-ap-cmdline-properties:
-init-macrodef-javac-with-processors:
-init-macrodef-javac-without-processors:
-init-macrodef-javac:
-init-macrodef-test-impl:
-init-macrodef-junit-init:
-init-macrodef-junit-single:
-init-test-properties:
-init-macrodef-junit-batch:
-init-macrodef-junit:
-init-macrodef-junit-impl:
-init-macrodef-testng:
-init-macrodef-testng-impl:
-init-macrodef-test:
-init-macrodef-junit-debug:
-init-macrodef-junit-debug-batch:
-init-macrodef-junit-debug-impl:
-init-macrodef-test-debug-junit:
-init-macrodef-testng-debug:
-init-macrodef-testng-debug-impl:
-init-macrodef-test-debug-testng:
-init-macrodef-test-debug:
-init-debug-args:
-init-macrodef-nbjpda:
-init-macrodef-debug:
-init-macrodef-java:
-init-presetdef-jar:
-init-ap-cmdline-supported:
-init-ap-cmdline:
init:
-deps-clean-init:
deps-clean:
-warn-already-built-clean:
[propertyfile] Updating property file: /home/jordi/NetBeansProjects/geneal/build/built-clean.properties
-do-clean:
[delete] Deleting directory /home/jordi/NetBeansProjects/geneal/build
-post-clean:
clean:
-pre-init:
-init-private:
-init-user:
-init-project:
-init-macrodef-property:
-do-init:
-post-init:
-init-check:
-init-ap-cmdline-properties:
-init-macrodef-javac-with-processors:
-init-macrodef-javac-without-processors:
-init-macrodef-javac:
-init-macrodef-test-impl:
-init-macrodef-junit-init:
-init-macrodef-junit-single:
-init-test-properties:
-init-macrodef-junit-batch:
-init-macrodef-junit:
-init-macrodef-junit-impl:
-init-macrodef-testng:
-init-macrodef-testng-impl:
-init-macrodef-test:
-init-macrodef-junit-debug:
-init-macrodef-junit-debug-batch:
-init-macrodef-junit-debug-impl:
-init-macrodef-test-debug-junit:
-init-macrodef-testng-debug:
-init-macrodef-testng-debug-impl:
-init-macrodef-test-debug-testng:
-init-macrodef-test-debug:
-init-debug-args:
-init-macrodef-nbjpda:
-init-macrodef-debug:
-init-macrodef-java:
-init-presetdef-jar:
-init-ap-cmdline-supported:
-init-ap-cmdline:
init:
-deps-jar-init:
deps-jar:
[mkdir] Created dir: /home/jordi/NetBeansProjects/geneal/build
-warn-already-built-jar:
[propertyfile] Updating property file: /home/jordi/NetBeansProjects/geneal/build/built-jar.properties
-check-automatic-build:
-clean-after-automatic-build:
-verify-automatic-build:
-pre-pre-compile:
[mkdir] Created dir: /home/jordi/NetBeansProjects/geneal/build/classes
-pre-compile:
-copy-persistence-xml:
-compile-depend:
-do-compile:
[mkdir] Created dir: /home/jordi/NetBeansProjects/geneal/build/empty
[mkdir] Created dir: /home/jordi/NetBeansProjects/geneal/build/generated-sources/ap-source-output
[javac] Compiling 30 source files to /home/jordi/NetBeansProjects/geneal/build/classes
[copy] Copying 1 file to /home/jordi/NetBeansProjects/geneal/build/classes
[copy] Copied 5 empty directories to 5 empty directories under /home/jordi/NetBeansProjects/geneal/build/classes
-post-compile:
compile:
-pre-jar:
-pre-pre-jar:
[mkdir] Created dir: /home/jordi/NetBeansProjects/geneal/dist
-do-jar-create-manifest:
-do-jar-copy-manifest:
[copy] Copying 1 file to /home/jordi/NetBeansProjects/geneal/build
-do-jar-set-mainclass:
-do-jar-set-profile:
-do-jar-set-splashscreen:
-do-jar-jar:
-init-macrodef-copylibs:
-do-jar-copylibs:
[copylibs] Copy libraries to /home/jordi/NetBeansProjects/geneal/dist/lib.
[copylibs] Building jar: /home/jordi/NetBeansProjects/geneal/dist/geneal.jar
[echo] To run this application from the command line without Ant, try:
[echo] java -jar "/home/jordi/NetBeansProjects/geneal/dist/geneal.jar"
-do-jar-delete-manifest:
-do-jar-without-libraries:
-do-jar-with-libraries:
-post-jar:
-do-jar:
jar:
BUILD SUCCESSFUL
Total time: 1 second
module来实现上述目标,在一定时间后终止密码提示。
所以我当前的代码看起来像这样
IPC::Run