Shell Script to delete files from 5 different servers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script to delete files from 5 different servers
# 1  
Old 03-19-2017
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.
Code:
find /path/to/files -type f -name "*log*" -mtime +10 -print -delete

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:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-19-2017 at 05:43 PM.. Reason: Added CODE tags.
# 2  
Old 03-19-2017
Welcome to the forum.

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".
This User Gave Thanks to RudiC For This Post:
# 3  
Old 03-19-2017
@RudiC

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

Code:
find /app/logs/httpd -type f -name "*log" -mtime +10 -print -delete

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.
Code:
class clearlogs {
        file {'/etc/cron.weekly/':
              ensure  => present,
              mode    => '0775',
              owner   => 'root',
              group    => 'root',
              source   => 'puppet:///modules/clearlogs/clearlogs.sh',
        }

        cron { 'clearinglogs':
                command   => 'sh /etc/cron.weekly/clearlogs.sh
                user           => 'root',
                weekday     => 'Sunday',
                hour           => '0',
                require       =>  File['/etc/cron.weekly/clearlogs.sh']
        }

}

And my clearlogs.sh looks like this and need to add the script for clearing logs on each server with this shell script
Code:
#!/bin/bash
echo "Deleting files in the location older than 10 days from now"

find /app/logs/httpd -type f -name "*log*" -mtime +10 -print -delete

echo "Successfully cleared logs!!!"

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:
Mod Comment 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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for connecting multiple servers and then copying 30 days old files

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)
Discussion started by: rcroyal88
1 Replies

2. Shell Programming and Scripting

Shell script to delete the ip address from files

Hello, I am new to shell scripting, need help, my requirement is to delete the ip address from serveral files, please suggest (2 Replies)
Discussion started by: manoj.solaris
2 Replies

3. Shell Programming and Scripting

Shell Script to delete the protected files.

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)
Discussion started by: Hadoop_Master
6 Replies

4. UNIX for Dummies Questions & Answers

Need a shell script to find 0 byte files in 5 servers

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)
Discussion started by: ChandruBala73
3 Replies

5. Shell Programming and Scripting

how to delete files on two remote servers simultaneously?

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)
Discussion started by: tiger2000
4 Replies

6. Shell Programming and Scripting

shell script to take input from a text file and perform check on each servers and copy files

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)
Discussion started by: joseph.dmello
0 Replies

7. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

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)
Discussion started by: hussa1n
2 Replies

8. Shell Programming and Scripting

shell script for delete old files

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)
Discussion started by: krishnarao
4 Replies

9. Shell Programming and Scripting

How to delete files in UNIX using shell script

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)
Discussion started by: theguy16
7 Replies

10. UNIX for Advanced & Expert Users

how to delete empty files in a shell script

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)
Discussion started by: rpnuge
1 Replies
Login or Register to Ask a Question