Shell Script to delete files from 5 different servers
Hello,
I'm new to shell scripting and need a quick note on how to write a shell script to perform deletion of files from 5 different hostnames in various locations.
Found out to delete files from one path by using below command and made it to work on cron job but need to do it in a shell script that should run on 5 servers at different file locations.
But here's is the trick there are files in different locations on each server. So how can i write a script to do in a single shot.
And each server got different hostname.
Thought of case could do me a favor.And ran out of ideas.
Please help me out.
Thanks,
Teja G
Moderator's Comments:
Please use CODE tags as required by forum rules!
Last edited by RudiC; 03-19-2017 at 05:43 PM..
Reason: Added CODE tags.
If you want more than just a few generic hints what could be done, your specification needs a way more precise problem description, and more details like input data & structure, network connectivity, servers' directory structures & file locations, dand possibly more.
Maybe some good starters are the links at the bottom left of this page under "More UNIX and Linux Forum Topics You Might Find Helpful".
So here are the file locations where i needed my files to be deleted on my servers.
Static Servers - /app/logs/httpd
Login Servers - /app/login/jetty/logs
Oauth Serves - /app/oauth-v2/jetty/logs
I did created and wrote for static servers as following
And there are 2 servers in the static group. So placed the script in cron job and its running fine on every Sunday 00:00 hrs.
But need the script attaching the above with Login and Oauth servers at the location specified in the same cron job. So it can run on static,login and oauth serves at same time using the same script.
So please guide me where to start from and which will be easier."Case, if...else, while or for"
Thanks,
Teja
---------- Post updated at 06:26 PM ---------- Previous update was at 06:01 PM ----------
The whole goal of mine is writing a puppet module to run the cron job on Every sunday, using the shell script to clear logs on servers.
The servers are as follows:
Static Servers - 5 with hostnames as static-1p.xyz.com; static-2p.xyz.com; static-3p.xyz.com; static-4p.xyz.com; static-5p.xyz.com
Logs stored in static servers at /app/logs/httpd
Login Servers - 5 with hostnames as login-1p.xyz.com; login-2p.xyz.com; login-3p.xyz.com; login-4p.xyz.com; login-5p.xyz.com
Logs stored in login servers at /app/login/jetty/logs
OAuth-v2 Servers - 5 with hostnames as oauth-1p.xyz.com; oauth-2p.xyz.com; oauth-3p.xyz.com; oauth-4p.xyz.com; oauth-5p.xyz.com
Logs stored in Oauth servers at /app/oauth/jetty/logs
So now I need to delete these logs by using a shell script that can place in my cron job weekly dir and i'll specify that script to run every sunday at 00hrs.
And here is my puppet code that does the job.
And my clearlogs.sh looks like this and need to add the script for clearing logs on each server with this shell script
This is only for one server static server, but i'm trying to write/add the lines to clear logs on other servers too in the same script.
So, please help me out or guide me with a roadmap where to start with and with what specific arguments i can accomplish my task to be successful...
Thanks,
Teja
Moderator's Comments:
Please use CODE (not ICODE) tags as required by forum rules!
Last edited by RudiC; 03-20-2017 at 05:13 AM..
Reason: Added & changed CODE tags.
Shell script for connecting multiple servers and then copying 30 days old files from those server .
HI ,
I have 6 multiple servers
pla1,pla2,pla3,pla4,pla5,pla6
1. These six servers have common shared mount point /var/share
2. Running script from /var/share to connect these servers.I... (1 Reply)
Hello,
we have more than 100000 files in a directory which are write-protected regular file, these files are quite old and would like to delete them completely, Kindly let me know the command or peice of code to automate the process.
The filenames are like below
MPNT_... (6 Replies)
Hi.....
Thanks for this wonderful forum....
My request:
I have toatally 5 unix servers in which many applications are working
I need to set a trap to identify 0 byte files if any are created proactively.
For example:
find /apps/fresco/ -mtime 1 -size 0c –print >>... (3 Replies)
dear all,
i'm preparing a script which can do these actions :
1. stop remove server's certain service
2. clean the files on remote servers simultaneously (because lots of files need to be deleted)
3. after files/logs are removed, restart the service again
i'm stuck on how to clean remote... (4 Replies)
HI all,
I want to script where all the server names will be in a text file like
server1
server2
server3 . and the script should take servernames from a text file and perform copy of files if the files are not present on those servers.after which it should take next servername till the end of... (0 Replies)
I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
i want to delete all the files in my directory except the latest one. i need to do this from shell script.
say i have
a.txt - latest file
b.txt,
c.txt..
it should delete all the files except a.txt? (4 Replies)
Hi,
I have the following task to perform using shell script.
The user will provide a directory name along with a date. The script will delete all the files in the specified directory that was created earlier to that date. Also it should display the number of files that has been deleted.
... (7 Replies)
I'm trying to figure out a way to delete empty files in a directory. I have a cron that runs and creates a flat file every 15 mins. However, most times at night the flat file will be empty.
I'd like to run a script to delete empty files that end with *.dat
Any suggestions?
Rich (1 Reply)