Reputation: 9898
Can anyone help me with the following. I think it could be due to whitespace but for the life of me I can't figure it out.
This is supposed to be a simple script that will move a file depending on it's location. I'm using expect as I want it to be handled on my NAS (via ssh), rather than taking the file off and putting it back on just to move it between shares.
#!/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'
}
Updated Code:
#!/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'
}
Debug Output
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
Upvotes: 1
Views: 376
Reputation: 280
change your = to ==
= is usually for assignment (and doesn't work in tcl. as commented below)
== is test for equalness
Upvotes: 1