Solved

Shell Scripting

Posted on 2001-08-23
3
342 Views
Last Modified: 2010-04-21
Hi,

  I`ve kinda lost touch with my shell scriprting and might have to write a shell script in the near future to go through the files in a directory and delete any file older than 45 days old. This is actually on a solaris5.6 machine. If anyone can help with pointers, tips, links to good sites and if possible the code itself , that would be great. I will be trying to write it myself of course but if all else fails(as i said i`m on a tight schedule), i want something to fall back on.

Help will be appreciated



0
Comment
Question by:infy_geek
3 Comments
 
LVL 1

Expert Comment

by:zmanz
Comment Utility
You could probably use the find command to do a search and destroy mission.
something like:  #find /directorytolookin  -mtime +45 -exec rm {} \;
I would test it using "ls -la" instead of "rm" first to make sure it does what you want it to do.

Look in your man page for the exact details of your implimenation: #man find
You may have to use something other than -mtime.

For tutorials go to www.google.com and to a search for something like: unix shell tutorial

0
 

Accepted Solution

by:
qiang8 earned 150 total points
Comment Utility
#!/usr/bin/bash    

echo "Removing old files in /home/user/data ... "
cd /home/user/data

for file in `find . -mtime +15 -print`
 do
   if [ -f $file ]
    then
     echo "Removing $file that existed more than 15 days."
     rm $file
     #use mv command to some temp dir for testing  
    fi
 done

You can cron this script (Bash shell) and perform a periodical clean up on your unwanted data. Cheers and good luck.
0
 

Author Comment

by:infy_geek
Comment Utility
Thanks giang. Your help was really useful. My boss suddenly made up his mind that he wnted the script today itself. Youre a life saver.

Thanks,
Alladin
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now