?
Solved

Shell Scripting

Posted on 2001-08-23
3
Medium Priority
?
352 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
ID: 6417316
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 450 total points
ID: 6452084
#!/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
ID: 6456346
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

864 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