Re: [OT] SSH login script - Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2009-04-24 at 11:16 +0100, Sharpe, Sam J wrote:
> Dan Track wrote:
> > 2009/4/24 Manuel Aróstegui <manuel@xxxxxxxxxxxxxx>:
> > > On Fri, 2009-04-24 at 10:12 +0100, Dan Track wrote:
> > >> Hi Guys,
> > >>
> > >> I've written a simple for loop see below:
> > >>
> > >> for i in orion earth;do scp /etc/hosts /etc;done
> > >>
> > >> I have a small scripting knowledge so would appreciate some help. What
> > >> I'd like to do is somehow change the above so that the script prompts
> > >> me for a password and when I give the script the password it will use
> > >> it to auto-reply to any password promtps that scp asks for when
> > >> logging into all the servers. If I am right I believe readline needs
> > >> to be used. If it can't be done in bash can you give me a perl
> > >> alternative please.
> > >>
> > >> Thanks for your help.
> > >>
> > >> Dan
> > >>
> > > Hi Dan,
> > >
> > > You might want to use autoexpect for that.
> > >
> > > This can get you in security problems since you'd need to write your
> > > password in the script, but as long as you use user and groups perms
> > > correctly you should kinda safe.
> > >
> > > Manuel.
> > >
> > Hi Manuel,
> >
> > Thankyou for your suggestion, is there any chance of getting the above
> > scripted by yourself. I've never used autoexpect before. I appreciate
> > the advice anyway.
> If security is not a concern, write a simple script that accepts the 
> password and provides it to sshpass (which isn't packaged for Fedora as 
> it's a huge huge security nightmare): http://freshmeat.net/projects/sshpass/
> 
> e.g.:
> [sam@sam ~]$ export SSHPASS=mypass
> [sam@sam ~]$ sshpass -e ssh unixdb2-vm
> [sam@unixdb2-vm ~]$
> 
> In your case, you'd want something like "sshpass -e scp /etc/hosts 
> orion:/etc/"
> 

Dan, 

The "magic" of autoexpec is that it does everything you do for you, here
you are an example:

First I start autoexpect and then I do whatever I want expect to do for
me
root@life:~# autoexpect 
autoexpect started, file is script.exp
root@life:~# ssh root@xxxxxxxxxxxx
root@xxxxxxxxxxxx's password: 
Last login: Fri Apr 24 12:45:04 2009 from 192.168.50.103
[root@galaga ~]# ls /opt/lzo-2.02/
aclocal.m4  autoconf  ChangeLog   config.log     configure.ac  examples
libtool   Makefile.am  NEWS    stamp-h1  util
asm         B         config.h    config.status  COPYING       include
lzotest   Makefile.in  README  tests
AUTHORS     BUGS      config.hin  configure      doc           INSTALL
Makefile  minilzo      src     THANKS
[root@galaga ~]# exit
logout
Connection to 192.168.50.1 closed.
root@life:~# exit
exit
autoexpect done, file is script.exp
root@life:~# chmod +x script.exp 

Now I execute my script:
root@life:~# ./script.exp 
spawn /bin/bash
root@life:~# ssh root@xxxxxxxxxxxx
root@xxxxxxxxxxxx's password: 
Last login: Fri Apr 24 12:46:01 2009 from 192.168.50.103
[root@galaga ~]# ls /opt/lzo-2.02/
aclocal.m4  autoconf  ChangeLog   config.log     configure.ac  examples
libtool   Makefile.am  NEWS    stamp-h1  util
asm         B         config.h    config.status  COPYING       include
lzotest   Makefile.in  README  tests
AUTHORS     BUGS      config.hin  configure      doc           INSTALL
Makefile  minilzo      src     THANKS
[root@galaga ~]# exit
logout
Connection to 192.168.50.1 closed.
root@life:

I had to change some minor stuff in script.exp to adapt it to my system
but all the major stuff is done automatically.

Anyways, as Joachim, you might want to read a little bit about expect
before trying this.

Manuel.

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux