【发布时间】:2014-06-10 18:20:09
【问题描述】:
我正在执行以下#!/bin/bash
###############################################################################
# This script can copy any file from Present machine to machine with IP as Test_ip and execute it :) #
###############################################################################
############################ Main code starts here ####################################
Test_ip="10.20.12.206"
home=`pwd`
expect -c "
spawn ssh root@$Test_ip \"mkdir /test_machine\"
expect yes/no { send yes\r; exp_continue }
expect password { send gaur\r; exp_continue }
exit
"
expect -c "
spawn scp $home/run_check_node.sh $home/script_3.sh $home/script_2.sh root@$Test_ip:/test_machine/
expect yes/no { send yes\r; exp_continue }
expect password { send gaur\r; exp_continue }
exit
"
expect -c "
spawn ssh root@$Test_ip \"chmod +x /test_machine/run_check_node.sh /test_machine/script_2.sh /test_machine/script_3.sh;\"
expect yes/no { send yes\r; exp_continue }
expect password { send gaur\r; exp_continue }
exit
"
expect -c "
spawn ssh root@$Test_ip \". /test_machine/script_2.sh\"
expect yes/no { send yes\r; exp_continue }
expect password { send gaur\r; exp_continue }
exit
"
显示的脚本是script_1.sh。
在上面的代码中,我在Test_ip 上创建了一个目录,然后使用scp 将所有3 个文件(script_2.sh、script_3.sh 和run_check_node.sh)从当前机器复制到另一台机器(Test_ip)。然后我给了他们执行权限。当我尝试执行spawn ssh root@$Test_ip \". /test_machine/script_2.sh\" 时,它正在接受密码,然后显示"/test_machine/script_2.sh: No such file or directory"。
我不明白为什么它会这样说。它只是让它们都可以执行,并且在下一个命令中,声称该文件不存在!
【问题讨论】:
-
看起来好像您将文件复制到 $home/script_2.sh 但尝试从 /test_machine/script_2.sh 执行它?
-
对于 scp,我正在将文件从
pwd复制到另一台机器上的test_machine目录。所以,一切都不像你想的那样。 -
scp命令的作用是:scp files_to_copy where_to_copy
-
哦,是的,对不起,我的错误
-
这个页面有更多相关信息[stackoverflow.com/questions/13298487/…这可能也值得一看。