I am looking for a beginner guide to shell scripting simple tasks on CentOS (e.g. ssh'ing into a server / router / switch, checking for certain things, then exiting and going to the next IP). Does anyone have any suggestions on where to look? (I'm relatively new to bash) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20101115/b2b5d1af/attachment-0001.html>
On 11/15/2010 01:47 PM, Kill Script wrote:> I am looking for a beginner guide to shell scripting simple tasks on > CentOS (e.g. ssh'ing into a server / router / switch, checking for > certain things, then exiting and going to the next IP). > > Does anyone have any suggestions on where to look? (I'm relatively new > to bash)The book Learning the bash Shell helped me out a lot. http://oreilly.com/catalog/9781565923478 Regards, Max
On Mon, Nov 15, 2010 at 04:47:02PM -0200, Kill Script wrote:> I am looking for a beginner guide to shell scripting simple tasks on CentOS > (e.g. ssh'ing into a server / router / switch, checking for certain things, > then exiting and going to the next IP). > > Does anyone have any suggestions on where to look? (I'm relatively new to > bash)I have a page where I've posted what I've found to be useful links. http://home.roadrunner.com/~computertaijutsu/shellscripting.html -- Scott Robbins PGP keyID EB3467D6 ( 1B48 077D 66F6 9DB0 FDC2 A409 FA54 EB34 67D6 ) gpg --keyserver pgp.mit.edu --recv-keys EB3467D6 Spike: A slayer with family and friends. That sure as hell wasn't in the brochure.
> Does anyone have any suggestions on where to look? (I'm relatively > new to bash)http://www.google.com/search?q=bash+tutorial has quite a few. I wrote a simple one a few years back: http://www.happyhacker.org/gtmhh/basha.shtml -- Spiro Harvey Knossos Networks Ltd (04) 460-2531 : (021) 295-1923 www.knossos.net.nz -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: not available URL: <http://lists.centos.org/pipermail/centos/attachments/20101116/3a141a77/attachment-0001.sig>
I wrote a simple one a few years back:> http://www.happyhacker.org/gtmhh/basha.shtmlThis is great! Thanks for sharing.
On 15/11/2010 18:47, Kill Script wrote:> I am looking for a beginner guide to shell scripting simple tasks on > CentOS (e.g. ssh'ing into a server / router / switch, checking for > certain things, then exiting and going to the next IP).If you don't want to use ssh keys, you will have to write scripts that interact with prompts, so you'll probably be looking at Expect, Python (pexpect or paramiko) or Perl.
#!/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 http://www.bsdmap.com/2010/11/06/ssh-shell-script/ ------------------ Original ------------------ From: "Kill Script"<killscript at gmail.com>; Date: Tue, Nov 16, 2010 02:47 AM To: "centos"<centos at centos.org>; Subject: [CentOS] good shell script examples? I am looking for a beginner guide to shell scripting simple tasks on CentOS (e.g. ssh'ing into a server / router / switch, checking for certain things, then exiting and going to the next IP). Does anyone have any suggestions on where to look? ?(I'm relatively new to bash) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20101117/dc49d92c/attachment-0001.html>
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- > > doneOr 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 at henderson-group.com 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 *********************************************************************************