nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

script to rm files on multiple servers

This is a discussion on script to rm files on multiple servers within the Shell scripting forums, part of the Development/Scripting category; Hello All, New guy to the " dark side " of command line and trying hard to improve/establish a decent ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 06-21-2008, 05:43 PM
Junior Member
User
 
Join Date: Jun 2008
My distro: rh
Posts: 1
Rep Power: 0
steve_f60 is on a distinguished road
Default script to rm files on multiple servers

Hello All,

New guy to the " dark side " of command line and trying hard to improve/establish a decent bash scripting ability. Have a need for a script sooner than later so I thought I would call out for help.

I need to have a bash script that can rm a file from multiple servers if logged onto one. Is there an easy way to do this?

I am thinking that I need a variable list of server names to use in the script along with just a simple rm /filepath.

Wouldn't I have to somehow " log into" each server to do the remove?
Would the script have to include an ssh to each server in the variable list ?

Trying to think out loud for this....

Thanks in advance for the help,
Steve
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-21-2008, 10:29 PM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 564
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

Steve,

Welcome to nixCraft forum!

Yes a script can be used to run files and all other stuff. First, you need to setup password less login using ssh-keys between your host and other servers:

Howto Linux / UNIX setup SSH with DSA public key authentication (password less login)

Howto use multiple SSH keys for password less login


The host will run a script, it will login to each system and it will remove files. Here is a sample script to kick start development:
Code:
#!/bin/bash
SERVERS="box1 box2 box3"
for b in $SERVERS
do
  ssh user@$b /bin/rm /path/to/file
done
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
how to change the format of multiple files in different directories dustcloud4 Shell scripting 0 06-05-2007 03:03 AM
login into multiple servers thru script... avcert1998 Shell scripting 2 03-17-2007 03:29 AM
Script to add users to multiple servers. deepakhg Shell scripting 0 03-17-2007 03:02 AM
shell script that parses multiple log files and checks for a Anonymous Shell scripting 1 11-15-2006 09:38 PM
multiple server status script marinm Linux software 20 08-03-2006 06:48 AM


All times are GMT +5.5. The time now is 04:36 PM.


Powered by vBulletin® Version 3.7.3 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36