Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

executing a command from within ftp->put()

Status
Not open for further replies.
Jul 28, 2004
726
BE
Hi all,

I'm trying to get the following to work :

from commandline I execute the following command :

ftp host
bin
put "|dd if=/dev/zero bs=4k count=100" /dev/null


this to test the troughput from the network


But when I try to put this into a perlscript , I get the error "No such file or directory".The command |dd .... doesn't get executed, instead it goes looking for an input file.


use FTP;
$remote_host="servername";
$ftp=Net::FTP->new("$remote_host",Debug => 1)|| die "$@ can't connect\n";
$ftp->login('root','password');
$ftp->binary();
$ftp->put("|dd if=/dev/zero bs=4k count=10 /dev/null");

Any suggestions how I can get this to work?

Thx in advance,

Regards,

RMGBelgium

 
try this

$ftp->site( "dd if=/dev/zero bs=4k count=10 /dev/null");

instead of

$ftp->put("|dd if=/dev/zero bs=4k count=10 /dev/null");

not sure, but it might just work

---
cheers!
san
smoking3vc.gif


print length "The answer to life, universe & everything!
 
ftp is a file transfer protocol, not a remote shell. I can't see how you can execute a command on a remote machine via ftp.

Maybe someone out there knows something that I don't. It wouldn't be the first time.


Trojan.


 
As far as I understand it Trojan is correct. To issue commands on the remote host you need to use the Net::Telnet module, not Net::FTP.
 
Hi 133tcamel,

tried your solution ,got "command not understood"

TrojanWarBlade,

This is the output I get with my command :

230 User root logged in.
ftp> bin
200 Type set to I.
ftp> put "|dd if=/dev/zero bs=32k count=100" /dev/null
200 PORT command successful.
150 Opening data connection for /dev/null.
100+0 records in
100+0 records out
226 Transfer complete.
3276800 bytes sent in 0.37 seconds (8648 Kbytes/s)
local: |dd if=/dev/zero bs=32k count=100 remote: /dev/null
ftp>


as you can see, this works ...

greetz

R.
 
Looks like I've learnt something new!
:)

Silly question, are you sure you're logging in with the same user details (userid and password). Have you tried absolute paths (ala "/bin/dd")?

Trojan


 
the command was issued with root , tried it with full path, same results
I got this trick from a guy at IBM , to measure the real troughput for the network ( from memory to memory ), but now I have to pour it into a script to use as a testscript for all our machines ....

greetz,

R.
 
Well, the dd just creates a 32k * 100 byte zero file. Assuming you have disk space to do so, you could precreate that (using the same command but redirect to a file) and "put" that.

Tony Lawrence
Linux/Unix/Mac OS X Resources
 
Try changing this:
Code:
$ftp->put("|dd if=/dev/zero bs=4k count=10 /dev/null");
to this:
Code:
$ftp->put("|dd if=/dev/zero bs=4k count=10","/dev/null");

And let me know what happens.

Trojan.

 
FTP isn't a good idea, IF you already know about SCP

I'm thinking there's already a number of modules on CPAN for network monitoring, might be worthwhile looking those up :)

--Paul

cigless ...
 
Hi Paul,

I know all about scp , but the clue of the whole story is that we are measuring troughput of the network, without any interference of disk activity, because the guys at networking their first thoughts are allways "its a problem with the unix servers", so with that command we can rule that out.

Trojan,

Tried your suggestion , no luck though...But thx for the replies !


regards

R.
 
Surely you'd be better to write something specifically to do this job.
You could have a little daemon process that runs on each machine and when connected to, will blast a specific volume of data back.

The trouble with your ftp idea is that it may not avoid disc access.

1) How can you be sure that the ftp server is not swapped out? You'd need to set the sticky bit to be sure (which you could do on a little daemon in the same way).
2) You're referencing /dev/null and /dev/zero. Strictly speaking, these are device files that live on a disk volume of some kind. Unix/Linux could (should?) access the disk to get the major and minor numbers of the device before zupplying the stream.

What do you think?

Trojan.

 
Hi trojan,

about the swapping, I don't thinks that I'll get swapped out, this test runs while nothing it started ( no db's, apps ), the servers have about 14 Gb memory, so chance is small that swap out will occur :)

strictly speaking you are right about the major number of the device, it is inevitable that you are going once or twice to disk, but with a stream of 40 Mb or so, these 2 accesses to disk won't influence the results

I solved the problem meanwhile using a ksh script.Preffered using Perl though ...
Thx for all your help !

Regards,

R.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top