|
From: <RGi...@a1...> - 2002-03-14 09:43:13
|
> I am using perl 5.6 with Expect module 1.12 and trying to get the
> size of a file on a remote server.
You don't need Expect for this, set up ssh with RSA key authentication
without passphrase (so ssh doesn't prompt for a password) and use ssh
directly:
$filesize = (split " ", qx{ssh user@host ls -l /path/to/file})[4];
or
$filesize = qx{ssh user@host perl -e 'print -s "/path/to/file"'};
chomp $filesize;
From the FAQ:
I want to automate password entry for su/ssh/scp/rsh/...
You shouldn't use Expect for this. Putting passwords,
especially root passwords, into scripts in clear text can
mean severe security problems. I strongly recommend using
other means. For 'su', consider switching to 'sudo', which
gives you root access on a per-command and per-user basis
without the need to enter passwords. 'ssh'/'scp' can be set
up with RSA authentication without passwords. 'rsh' can use
the .rhost mechanism, but I'd strongly suggest to switch to
'ssh'; to mention 'rsh' and 'security' in the same sentence
makes an oxymoron.
It will work for 'telnet', though, and there are valid uses
for it, but you still might want to consider using 'ssh', as
keeping cleartext passwords around is very insecure.
I want to use Expect to automate [anything with a buzzword]...
Are you sure there is no other, easier way? As a rule of
thumb, Expect is useful for automating things that expect to
talk to a human, where no formal standard applies. For
other tasks that do follow a well-defined protocol, there
are often better-suited modules that already can handle
those protocols. Don't try to do HTTP requests by spawning
telnet to port 80, use LWP instead. You don't use a
screwdriver to hammer in your nails either, or do you?
Hope this helps,
Roland
--
RGi...@cp...
|