-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathuload.sh
More file actions
executable file
·54 lines (54 loc) · 1.46 KB
/
Copy pathuload.sh
File metadata and controls
executable file
·54 lines (54 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/expect
#If it all goes pear shaped the script will timeout after 20 seconds.
set timeout 20
#First argument is assigned to the variable ip
set ip [lindex $argv 0]
#Second argument is assigned to the variable port
set port [lindex $argv 1]
#Third argument is assigned to the variable filename
set remotefilename [lindex $argv 2]
set filename [lindex $argv 3]
#prep file content
set fp [open "$filename" r]
set file_data [read -nonewline $fp]
close $fp
# Process data file
set data [split $file_data "\n"]
#This spawns the telnet program and connects it to the variable ip
spawn telnet $ip $port
#The script expects login
#expect "Connected to $ip."
expect "Escape character is '^]'."
sleep 1
send "if true == file.open(\"$remotefilename\", \"w+\") then \r"
expect ">>"
send "print(\"ok\")\r"
expect ">>"
send "end\r"
expect "ok"
foreach line $data {
# do some line processing here
expect ">"
#replace all ' with \'
regsub -all {\\r} $line {\\\\r} line
regsub -all {\\n} $line {\\\\n} line
regsub -all {'} $line {\\'} line
puts "writing $line"
send "if true == file.writeline('$line') then \r"
expect ">>"
send "print(\"ok\")\r"
expect ">>"
send "end\r"
expect "ok"
}
expect ">"
send "file.flush()\r"
expect ">"
send "file.close()\r"
expect ">"
send "print(\"done\")\r"
expect "done"
sleep 1
close
#This hands control of the keyboard over two you (Nice expect feature!)
#interact