?
Solved

Shell Scripting

Posted on 2001-08-23
3
Medium Priority
?
348 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

770 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