Extracting an ipaddress and using it to send files but error at the end of file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Extracting an ipaddress and using it to send files but error at the end of file
# 1  
Old 05-19-2014
Extracting an ipaddress and using it to send files but error at the end of file

i want to extract ip address from a file and using that ip address copy file to systems.
Code:
set fid [open /root/hosts.txt r]
set content [read $fid]
close $fid

## Split into records on newlines
set records [split $content "\n"]
send "records splited\n"
send $records\n
set timeout 600
set a "test\n"
send $a
foreach rec $records { 

   ## Split into fields on colons
   set fields [split $rec "/n"]
#set fields [split $records "\n"]
puts $fields

   spawn scp /home/test/temp.txt test@$fields:/home/test/
   #expect "*yes/no*" { send "yes\r"}   
   expect "*root@$fields's password:*" { send "serious\r" }
   expect eof

}

through the above code i am able to copy files to all the ip_address mentioned in the file but it gives me an error once it has completed sending files to all ips
as there is no ipaddress at it gives me this error:
Code:
error: spawn scp /home/test/temp.txt test@:/home/test/
Could not resolve hostname : Name or service not known

what all changes need to made in the code to avoid this error

Last edited by vbe; 05-19-2014 at 08:41 AM.. Reason: code tags please, not ICODE ... (+ extra code tags...)
# 2  
Old 05-19-2014
It might help to post a (sample of) the file you are trying to parse. Most probably it is an empty line at the end of your input file which causes the problem, but this is just wild guessing.

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting vaules from end of string

I'm trying to write a script which will calculate percentages from a printer. I have a command snmpwalk -v1 -c public 192.168.0.20 1.3.6.1.2.1.43.11.1.1.9.1.1 which returns (current ink level): iso.3.6.1.2.1.43.11.1.1.9.1.1 = INTEGER 235 then a similar command which returns similar output but... (7 Replies)
Discussion started by: leshy93
7 Replies

2. Shell Programming and Scripting

Joining files using awk not extracting all columns from File 2

Hello All I'm joining two files using Awk by Left outer join on the file 1 File 1 1 AA 2 BB 3 CC 4 DD File 2 1 IND 100 200 300 2 AUS 400 500 600 5 USA 700 800 900 (18 Replies)
Discussion started by: venkat_reddy
18 Replies

3. Shell Programming and Scripting

How to get CRC check sum of files in java EAR file without extracting .jar/.war files to disk.?

unzip -v gives CRC info of each file in a zip(in my case .EAR) file. # unzip -v my-application.ear Archive: my-application.ear Length Method Size Cmpr Date Time CRC-32 Name -------- ------ ------- ---- ---------- ----- -------- ---- 197981 Defl:N 183708 7%... (1 Reply)
Discussion started by: kchinnam
1 Replies

4. Shell Programming and Scripting

IF section problem. syntax error: unexpected end of file error

Hello, I have another problem with my script. Please accept my apologies, but I am really nooby in sh scripts. I am writing it for first time. My script: returned=`tail -50 SapLogs.log | grep -i "Error"` echo $returned if ; then echo "There is no errors in the logs" fi And after... (10 Replies)
Discussion started by: jedzio
10 Replies

5. Shell Programming and Scripting

Fetch ipaddress and hostname from host file.

hello guys, I have a query ,I am looking for a unix command using awk and grep that help me fetching a particular ip address and hostname from the host file.........?????? (3 Replies)
Discussion started by: Pawan Ramnani
3 Replies

6. Shell Programming and Scripting

Get the ipaddress and align based on the input file

Hi All, I have a file contains below contents, "interfacename/subnet: public (or) interfacename/subnet:cluster_interconnect" "en2"/10.185.81.0:cluster_interconnect,"en5"/10.185.81.0:cluster_interconnect,"en6"/169.181.146.0:public... (6 Replies)
Discussion started by: kamauv234
6 Replies

7. UNIX for Dummies Questions & Answers

grep specific ipaddress from a file

All, Iam new to unix and i have 1 requirement, can anyone help me please I have provided the file below, i will be having similar files in 100+clients systems. i want to check the the ip address "192.168.208.40" and if it is present then i should get a mail alert, if the ip address is not... (1 Reply)
Discussion started by: tbd
1 Replies

8. UNIX for Dummies Questions & Answers

Extracting specific files from a tar file in HP-UX

I have tried: tar -xfv mytarfile.tar archive/tabv/* tar -xfv mytarfile.tar --wildcards 'archive/tabv/*' tar -xf mytarfile.tar -v --wildcards 'archive/tabv/*' tar -xfv mytarfile.tar --wildcards --no-anchored 'archive/tabv/*' tar -xfv mytarfile.tar --wildcards `archive/tabv/*` and none... (5 Replies)
Discussion started by: zapper222
5 Replies

9. Shell Programming and Scripting

replacing files in an EAR file after extracting

{Hello All, Here is what I am trying to do: I have an archive file: AppName.ear jar -tvf AppName.ear 60459 Thu May 01 09:29:36 EDT 2008 /SharedResources/Application/App.dat 67542 Thu May 01 09:29:36 EDT 2008 JDBCConn/Application/App.dat 14488 Thu May 01 09:29:36 EDT 2008 config.xml ... (0 Replies)
Discussion started by: chiru_h
0 Replies

10. UNIX for Dummies Questions & Answers

Is extracting specific files from a zip file possible?

If a zip file contains several zip files, but if the file names of the files needed are known, is there a variation of the unzip command that will allow those few (individual) files to be extracted? --- Example: Zip file name: zip.zip unzip -l zip.zip will display file01, file02, file03, etc.... (1 Reply)
Discussion started by: HLee1981
1 Replies
Login or Register to Ask a Question