Re: good shell script examples?

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



On Wednesday 17 Nov 2010 07:47:17 æãå wrote:
> #!/bin/bash
> 
> 
> H="
> 192.168.1.1
> 192.168.1.2
> 192.168.1.3
> 192.168.1.4
> "
> 
> 
> for i in $H ; do
>     expect << -EOF-
> set timeout 2
> spawn scp ${rootidfile} root@${host}:/tmp/id_file
> expect "d:"
> send "${password}\n"
> expect eof
> spawn ssh ${host}
> expect "d:"
> send "${password}\n"
> expect "#"
> send "mkdir -p /root/.ssh; chmod 700 /root/.ssh\n"
> expect "#"
> send "cat /tmp/id_file >> /root/.ssh/authorized_keys\n"
> expect "#"
> send "rm -f /tmp/id_file; exit\n"
> expect eof
> -EOF-
> 
> done

Or have a look at Fabric [1] which deals with SSH, sudo, passwords, etc. and 
multiple hosts so it would be a matter of:

  @hosts('192.168.1.1', '192.168.1.2', '192.168.1.3', '192.168.1.4')
  def some_task():
      put('rootidfile', '~/.ssh/authorized_keys')

and run it as:

  $ fab -U root some_task


[1] http://fabfile.org/


-- 
Michael Gliwinski
Henderson Group Information Services
9-11 Hightown Avenue, Newtownabby, BT36 4RT
Phone: 028 9034 3319

**********************************************************************************************
The information in this email is confidential and may be legally privileged.  It is intended solely for the addressee and access to the email by anyone else is unauthorised.
If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful.
When addressed to our clients, any opinions or advice contained in this e-mail are subject to the terms and conditions expressed  in the governing client engagement leter or contract.
If you have received this email in error please notify support@xxxxxxxxxxxxxxxxxxx

John Henderson (Holdings) Ltd
Registered office: 9 Hightown Avenue, Mallusk, County Antrim, Northern Ireland, BT36 4RT.
Registered in Northern Ireland
Registration Number NI010588
Vat No.: 814 6399 12
*********************************************************************************

_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos



[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux