How to upload a file into 2 servers at the same time.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to upload a file into 2 servers at the same time.
# 1  
Old 04-03-2008
How to upload a file into 2 servers at the same time.

Hi, I'm new to unix/ Perl CGI. I have written Perl CGI scripts to upload a file into 2 servers at the same time using url redirection. But what happens is when i upload the file, it is getting uploaded in the first server properly and an empty file is uploaded in the second server( with the same filename- 0 bytes). An error saying: 'readline() on unopened filehandle at /var/apache/cgi-bin/uploadscr2 line 29 'comes in the error_log of the second server. I submit my script here:

( The follow script is in the cgi-bin of the first server- http://server1 root/cgi-bin/uploadscr1)

#!/usr/bin/perl -w
use CGI;
$query = new CGI;

$upload_dir = "/usr/tmp";

$FILENAME = $query->param("photo");
$FILENAME =~ s/.*[\/\\](.*)/$1/;

$upload_filehandle = $query->upload("photo");

open UPLOADFILE, ">/usr/tmp/$FILENAME";

binmode UPLOADFILE;

while ( <$upload_filehandle> )
{
print UPLOADFILE;
}

close UPLOADFILE;

print $query->redirect(" http://server2 root/cgi-bin/uploadscr2?file=$FILENAME&photo=$upload_filehandle");

==============================================

( this script is in the cgi-bin of the second server, the url mentioned above goes to this script)

#!/usr/bin/perl -w
use CGI;

$upload_dir = "/usr/tmp";
$q = new CGI;

print $q->header ( );
print " <HTML><HEAD></HEAD><BODY>";

$FILENAME = $q->param('file');
$FILENAME =~ s/.*[\/\\](.*)/$1/;

$upload_filehandle = $q->upload('photo');

print " <BR>FILENAME = ".$FILENAME."<BR>";

open UPLOADFILE, ">/usr/tmp/$FILENAME";

binmode UPLOADFILE;

while ( <$upload_filehandle> ) # error message refers to this line
{
print UPLOADFILE;
}

close UPLOADFILE;

print "<P>Thanks for uploading a file!</P></BODY></HTML>";

=================================================

Please bare with me if my script is bad, but i will be very thankful if someone can clear my doubt.

Thank you in advance.
# 2  
Old 04-05-2008
When the first while loop ends, the client has stopped sending data.

You can simply upload /usr/tmp/$FILENAME with a new HTTP session from the first server to the second. I don't think your redirect idea will work.
# 3  
Old 04-06-2008
Thank you, but could you please give me a sample script so as to how ur idea will work
# 4  
Old 04-10-2008
Network

I tried giving a new http in the first script itself for upload, but it didnt work. Is there any method to upload files using http?

Pls help..
# 5  
Old 04-10-2008
That's what your clients are doing when they upload a file to you, no?
# 6  
Old 04-10-2008
The client is selecting the file from his/her system and sending it to the script thru form action.

I want to know how to mentioned the path of the second server's usr/tmp in the first server's script itself, so that i can do upload twice in the first script( one to server1 and other to server2) without using a redirect.
# 7  
Old 04-10-2008
Your CGI script can submit a form to server 2, just like your client.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Comparing time differences between 2 Solaris servers

Good day to all. I'm relatively new in using the Sun Solaris OS. I would like to request your expertise in helping to solve a problem that I have at work. Not sure if this has been asked before but I have tried searching through the internet to no avail. Basically I have 2 sun solaris... (8 Replies)
Discussion started by: Fossil_84
8 Replies

2. AIX

Time of query execution much different between 3 servers

Hello, I have 3 AIX 6.1 machines running INFORMIX 11.7 database engine. One of these servers is the database server and the other 2 servers are connecting to it. I am doing a test to determine the time of query execution between these servers and i see that in specific times one of these... (12 Replies)
Discussion started by: omonoiatis9
12 Replies

3. UNIX for Dummies Questions & Answers

How can we connect multiple servers at a time?

help me (0 Replies)
Discussion started by: sonu pandey
0 Replies

4. Shell Programming and Scripting

Run a shell script on all 15 servers at the same time?

We have 15 servers. Hostnames for these 15 servers are stored in a text files and loop through each server to connect to the remote server and run a command, but this loop process runs the command one after another. However, the requirement is to run the same command on all 15 servers at the same... (10 Replies)
Discussion started by: laknar
10 Replies

5. UNIX for Dummies Questions & Answers

Want to practice UNIX in real time servers

I have read enough books and know about all the basic commands in unix. I have practiced the same in my home. Now i want to real time work like scheduling cron in a real time server, creating alerts, application status check using unix etc.., I want to have a real time server acc to do this kind... (3 Replies)
Discussion started by: gk1227
3 Replies

6. UNIX for Dummies Questions & Answers

ksh to check second time difference between two servers

I am currently setting up a public key authentication between servers. The goal is to get the date via `ssh hostname date` on all the 4 remote servers , put the value in a text file on the central server and compare the date (specifically seconds) for each server date output to check if time is... (7 Replies)
Discussion started by: depam
7 Replies

7. Shell Programming and Scripting

Need bash script to ping the servers and rename the output file each time the script is ran

HI, I have a file serverlist in that all host names are placed. i have written a small script #./testping #! /bin/bash for i in `cat serverlist` do ping $i >> output.txt done so now it creates a file output.txt till here fine.. now each time i run this script the output file... (4 Replies)
Discussion started by: madhudeva
4 Replies

8. AIX

Synchronize time on several AIX servers ?

Hi, I want to synchronize time on several AIX servers - I don't want to set very precise time value, but I want all the servers to have same time value. How do I do that ? thanks Vilius (2 Replies)
Discussion started by: vilius
2 Replies

9. UNIX for Dummies Questions & Answers

Need to calculate sftp time beteen two servers.

Hi, I need to calculate time taken by a 100kb file for sftp between two servers. I am new to unix can some body please tell me how do this. Thanks in advance... Vivek (2 Replies)
Discussion started by: koulvivek
2 Replies

10. AIX

How to change time on servers

Hi all We are currently using AIX 5.3, we reuquire to change the time according to the daylight saving scenario. We are using the internal clock and are not synced with ntp server. Can any one please tell me how to do that without effecting the processes running on the servers? (2 Replies)
Discussion started by: masquerer
2 Replies
Login or Register to Ask a Question