- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Need a script !
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2006 07:39 AM
09-01-2006 07:39 AM
We have a backup job which creates a directory everyday with the name of the day. I would like to delete the directory 2days old every day at 6:00 sothat it will not fillup the filesystems.
root@hp01:/backup# ll
total 0
drwxr-x--- 2 root sys 96 Aug 30 12:35 20060830
drwxr-x--- 2 root sys 96 Aug 31 12:35 20060831
drwxr-x--- 2 root sys 96 Sep 1 12:35 20060901
root@hp01:/backup#
How can i do this ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2006 07:42 AM
09-01-2006 07:42 AM
Re: Need a script !
find /backup -xdev -ctime +2 -type f -exec rm {} \;
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2006 07:44 AM
09-01-2006 07:44 AM
Re: Need a script !
Invoke command: crontab -e
and add following line which will run at midnight 12:00am everyday.
0 0 * * * find /backup -xdev -ctime +2 -type f -exec rm {} \;
- Tags:
- crontab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2006 07:46 AM
09-01-2006 07:46 AM
Re: Need a script !
If you want to delete the directory:
# find /backup -type d -mtime +2 -exec rm -rf {} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2006 07:48 AM
09-01-2006 07:48 AM
Solution--------------------------------------
#!/usr/bin/sh
PATH=${PATH}:/usr/bin:/usr/local/bin
export PATH
typeset DTMINUS2=""
typeset BDIR=/backup
typeset DNAME=""
typeset -i STAT=0
DTMINUS2=$(caljd.sh -y -s $(caljd.sh -p 2))
DNAME=${BDIR}/${DTMINUS2}
if [[ -d "${DNAME}" ]]
then
rm -rf "${DNAME}"
STAT=${?}
fi
exit ${STAT}
--------------------------------
Now download the attached caljd.sh and install it in /usr/local/bin and make it executable.
Invoke as caljd.sh -u for usage and example to see what it is doing.
- Tags:
- caljd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2006 08:55 AM
09-01-2006 08:55 AM
Re: Need a script !
You could also use this:
# cd /backup && perl -MPOSIX=strftime -e '$name=strftime("%Y%m%d",localtime(time-(86400*2)));system("rm -r $name")'
Regards!
...JRF...
- Tags:
- Perl