Solved

Shell Scripting

Posted on 2001-08-23
3
343 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 150 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
A short film showing how OnPage and Connectwise integration works.

930 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