任何人都可以帮助我以下内容。我认为这可能是由于空白,但对于我的生活,我无法弄明白。
这应该是一个简单的脚本,它将根据文件的位置移动文件。我正在使用expect,因为我希望它可以在我的NAS上处理(通过ssh),而不是取消文件并将其重新放回以便在共享之间移动它。
#!/usr/bin/expect -f
# Script to organise downloaded file
set FileDir [lindex $argv 0]
set FileName [lindex $argv 1]
set MiscDir "/media/Misc/Downloads"
set DownDir "/media/Downloads"
if { [string compare $FileDIR $DownDir] = 0 } {
} elseif { [string compare $FileDIR $MiscDir] = 0 } {
spawn ssh *****@*******
expect "assword:"
send "********\r"
expect "$ "
send "mv ~/Misc/Downloads/$FileNAME '~/Misc/To Convert/$FileNAME'"
expect "$ "
send "exit\r"
expect eof'
}
更新代码:
#!/usr/bin/expect -f
# Script to organise downloaded file
set FileDir [lindex $argv 0]
set FileName [lindex $argv 1]
set MiscDir "/media/Misc/Downloads"
set DownDir "/media/Downloads"
if { [string compare $FileDir $DownDir] == 0 } {
} elseif { [string compare $FileDir $MiscDir] == 0 } {
set OrigFile "\"/shares/Misc/Downloads/$FileName\""
set MoveFile "\"/shares/Misc/To Convert/$FileName\""
spawn ssh Admin@Appledore
expect "assword:"
send "xxxxxxxx\r"
expect "$ "
send "mv $OrigFile $MoveFile"
expect "$ "
send "exit\r"
expect eof'
}
调试输出
spawn ssh Admin@Appledore parent: waiting for sync byte parent: telling child to go ahead parent: now unsynchronized from child spawn: returns {5222}
expect: does "" (spawn_id exp6) match glob pattern "assword:"? no Admin@appledore's password: expect: does "Admin@appledore's password: " (spawn_id exp6) match glob pattern "assword:"? yes expect: set expect_out(0,string) "assword:" expect: set expect_out(spawn_id) "exp6" expect: set expect_out(buffer) "Admin@appledore's password:" send: sending "*******!\r" to { exp6 }
expect: does " " (spawn_id exp6) match glob pattern "$ "? no
expect: does " \r\n" (spawn_id exp6) match glob pattern "$ "? no [Admin@Appledore ~]$ expect: does " \r\n[Admin@Appledore ~]$ " (spawn_id exp6) match glob pattern "$ "? yes expect: set expect_out(0,string) "$ " expect: set expect_out(spawn_id) "exp6" expect: set expect_out(buffer) " \r\n[Admin@Appledore ~]$ " send: sending "mv "/shares/Misc/Downloads/NOOBS_lite_v1_4.zip" "/shares/Misc/To Convert/NOOBS_lite_v1_4.zip"" to { exp6 }
expect: does "" (spawn_id exp6) match glob pattern "$ "? no <ownloads/NOOBS_lite_v1_4.zip" "/shares/Misc/To Convert/NOOBS_lite_v1_4.zip" expect: does "mv "/shares/Misc/Downloads/NOOBS_lite_v1_4.zip" "/shares/Misc/To Convert/NOOBS_lite_v1_4.zip\r<ownloads/NOOBS_lite_v1_4.zip" "/shares/Misc/To Convert/NOOBS_lite_v1_4.zip" \u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008\u0008" (spawn_id exp6) match glob pattern "$ "? no
答案 0 :(得分:1)
将你的=改为==
=通常用于赋值(并且在tcl中不起作用,如下所述)
==是对同等性的测试