LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-21-2011, 05:26 AM   #1
netha
LQ Newbie
 
Registered: Apr 2011
Posts: 2

Rep: Reputation: 0
unix shell script for housekeeping


Hi everyone,

i have to write a shell script that will delete all the .dat files in /var/oracle/etl/incoming which the created date of the file is 7 days before the currrent date.

since i'm a newbie to unix, i have no idea how to write it!!!
kindly pls help buddies....

thanks in advance!!!!
 
Old 04-21-2011, 05:30 AM   #2
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
so if i'm getting it right, you have to delete all .dat files in that folder which are 7 days old? (7 days or less or 7 days or more)??
 
Old 04-21-2011, 05:44 AM   #3
X.Cyclop
Member
 
Registered: Jun 2006
Location: Tlv
Distribution: Arch!
Posts: 120

Rep: Reputation: 21
Code:
find /var/oracle/etl/incoming '*.dat' -mtime +7 -exec rm {} \;

Last edited by X.Cyclop; 04-21-2011 at 05:48 AM.
 
1 members found this post helpful.
Old 04-21-2011, 05:58 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
A shell script is essentially a series of commands. In this case you only need one command, as already given:
Quote:
Originally Posted by X.Cyclop View Post
Code:
find /var/oracle/etl/incoming '*.dat' -mtime +7 -exec rm {} \;
With correction and safety:
Code:
find /var/oracle/etl/incoming -name '*.dat' -mtime +7 -exec echo rm {} \;
Remove the echo when you are confident it is going to remove the files you want to remove.
 
3 members found this post helpful.
Old 04-21-2011, 08:38 AM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,549
Blog Entries: 23

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
Hi,

Welcome to LQ!

Quote:
Originally Posted by netha View Post
Hi everyone,

i have to write a shell script that will delete all the .dat files in /var/oracle/etl/incoming which the created date of the file is 7 days before the currrent date.

since i'm a newbie to unix, i have no idea how to write it!!!
kindly pls help buddies....

thanks in advance!!!!
Sure sounds like homework to me. What have you done to find a solution to the problem? Other than to post here.

We will aid you when you help yourself to a solution. Provide us with what you have attempted and then maybe someone will be able to assist. To spoon feed member answers for homework helps no one, especially the requester.

As the LQ Rules state;
Quote:
Do not expect LQ members to do your homework - you will learn much more by doing it yourself.
FYI: I suggest that you look at 'How to Ask Questions the Smart Way' so in the future your queries provide information that will aid us in diagnosis of the problem.



For scripting I suggest that you look at 4,5 & 6 below.

Just a few links to aid you to gaining some understanding;



1 Linux Documentation Project
2 Rute Tutorial & Exposition
3 Linux Command Guide
4 Bash Beginners Guide
5 Bash Reference Manual
6 Advanced Bash-Scripting Guide
7 Linux Newbie Admin Guide
8 LinuxSelfHelp
9 Utimate Linux Newbie Guide

The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
 
Old 04-21-2011, 10:49 PM   #6
netha
LQ Newbie
 
Registered: Apr 2011
Posts: 2

Original Poster
Rep: Reputation: 0
Talking Thank you all!!!

Quote:
Originally Posted by catkin View Post
A shell script is essentially a series of commands. In this case you only need one command, as already given:
With correction and safety:
Code:
find /var/oracle/etl/incoming -name '*.dat' -mtime +7 -exec echo rm {} \;
Remove the echo when you are confident it is going to remove the files you want to remove.
rely appreciate wat u all have replied... Thank you!!!
 
Old 04-22-2011, 09:16 AM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
If the issue is solved, mark the thread as solved.
 
Old 04-22-2011, 09:54 AM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
I'm with onebuck on the homework issue but a solution had already been offered
 
Old 04-22-2011, 10:54 AM   #9
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,549
Blog Entries: 23

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
Hi,

Too many members just shoot answers without considering consequences for the OP. Sure, answered but did the poster learn anything other than copy & paste?

As a member I would like to see others think about shot-gunning solutions. Would you want someone that could perform, possibly stumble while in training to learn or someone that gets the answer then graduates and then fails? I would not hire the latter!

There's a time for spoon feeding and a time to address a posters attempt at the tasks. Throwing out answers helps no one, not even the member who already knows the answer. Try to model your answer to help the poster to understand not flat out doing the task(s).
Quote:
Do not expect LQ members to do your homework - you will learn much more by doing it yourself.
This LQR is simple but justifiable, reasonable and should be the controlling factor when addressing homework so the poster can learn. We may need to assist yet not do it.
 
Old 05-22-2012, 03:34 PM   #10
oldyankee
LQ Newbie
 
Registered: Dec 2011
Posts: 4

Rep: Reputation: Disabled
Lightbulb [SOLVED] unix shell script for housekeeping

In support of what Gary said, I believe the old adage about giving a fish to a man applies:

Give a man a fish and he will eat for a day.
Teach a man to fish and he will steal all of the big ones in your pond.
 
Old 05-22-2012, 09:53 PM   #11
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 806

Rep: Reputation: 186Reputation: 186
Sure a student, but may be self study (of the Oracle 10G infrastructure)
http://linux.bigresource.com/General...JmDUpMIrG.html

Just following the link there for view replies points me back to LQ.

OK

Last edited by AnanthaP; 05-22-2012 at 10:18 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unix shell script question redss Programming 18 09-07-2012 05:40 AM
Shell Script and Administration of a UNIX System Hi_This_is_Dev Programming 10 08-30-2010 04:24 AM
Shell Script for Unix Date ??? ajeetraina Linux - Newbie 11 02-08-2008 01:58 AM
JCLs in Mainframes to UNIX Shell Script nirmal.garga Linux - Software 1 02-13-2006 10:48 AM
unix shell script cxy0481 Programming 9 11-20-2005 09:15 AM


All times are GMT -5. The time now is 09:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration