Please excuse my noobiness, I’ve just been learning TCL a few days now and have little coding experience except a rudimentary understanding of Expect.
I have a NAS with a bunch of files that I’d like to rename. I want to create a script which will generate the commands to name the files from “this” to “that.” Below is a quick example of how I’m going about this.
#!/usr/bin/tcl
set src1 myfilename1.txt
set src2 myfilename2.txt
set src3 myfilname3.txt
set dst1 mynewfilename1.txt
set dst2 mynewfilename2.txt
set dst3 mynewfilename3.txt
set count 0
set log [open output.txt w]
while { $count < 4 } {
set count [incr $count]
set srcName "src$count"
set dstName "dst$count"
puts $log "mv $srcName $dstName"
}
close $log
#!/usr/bin/tcl
set src(1) "myfilename1.txt"
set src(2) "myfilename2.txt"
set src(3) "myfilname3.txt"
set dst(1) "mynewfilename1.txt"
set dst(2) "mynewfilename2.txt"
set dst(3) "mynewfilename3.txt"
set count 0
set log [open output.txt w]
while {$count < 3} {
incr count
set srcName $src($count)
set dstName $dst($count)
puts $log "mv $srcName $dstName"
}
close $log
You should probably have the tcl script actually do the file renaming, and as mentioned above, mv is not a tcl command:)
That is exactly what I wanted. The output was to go to a text file which I could copy/paste into an SSH session. It would have been ideal to write this in Expect, as I could send the commands I want within the SSH session, but I didn't know how to do the loop with the variables. I think I have enough now to migrate this over to Expect. I appreciate the help.