Solved

what this cleanit functino does?

Posted on 2013-01-08
12
195 Views
Last Modified: 2013-01-16
Dear all:

when i am reading a backup script, i found this line is hard to understand, could you explain it to me a bit? Thank you in advance.


# The number of days to delete during the cleanIt function
delDays=+5

cleanIt () {

# This script clean the old data off of the drive. The var $delDays tells the script how many days to delete.
sleep 20
rm -rf $(find /u1/backupdisk/ -maxdepth 1 -mtime $delDays|sed '1 d' |grep backup)
}


I don't understand the parameters behind rm -rf.

"rm -rf $(find /u1/backupdisk/ -maxdepth 1 -mtime $delDays|sed '1 d' |grep backup)"

Thanks.
0
Comment
Question by:Jason Yu
[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
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 20

Assisted Solution

by:netcmh
netcmh earned 251 total points
ID: 38757301
That command will delete files inside /u1/backupdisk directory older than 5 days with the word backup in the name.
0
 

Author Comment

by:Jason Yu
ID: 38757303
then what does this part mean: sed '1 d' ?
0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 83 total points
ID: 38757334
It deletes the first line
0
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 166 total points
ID: 38757338
sed 1d removes the first line of output from the find command, so it effectively leaves one backup file in the directory.

It is better written as:
find /u1/backupdisk/ -maxdepth 1 -name "*backup*" -mtime $delDays|xargs rm -f

Open in new window

0
 

Author Comment

by:Jason Yu
ID: 38757389
If I want to delete the old archives in this folder /u2/backup/luna

as listed:

[root@titan luna]# ls -l
total 268723836
-rw-r--r--  1 nfsnobody nfsnobody 31380309423 Dec  3 22:51 luna.minkagroup.net20121203.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody 31386717967 Dec  4 22:45 luna.minkagroup.net20121204.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody 31392048069 Dec  5 22:43 luna.minkagroup.net20121205.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody 31397210055 Dec  6 22:45 luna.minkagroup.net20121206.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody 31401869675 Dec  7 22:54 luna.minkagroup.net20121207.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody 31591944161 Dec 10 22:50 luna.minkagroup.net20121210.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody 31597450665 Dec 11 22:52 luna.minkagroup.net20121211.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody 30313918464 Dec 12 22:39 luna.minkagroup.net20121212.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody       98304 Dec 13 20:25 luna.minkagroup.net20121213.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 14 20:24 luna.minkagroup.net20121214.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 17 20:25 luna.minkagroup.net20121217.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 18 20:23 luna.minkagroup.net20121218.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 19 20:21 luna.minkagroup.net20121219.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 20 20:24 luna.minkagroup.net20121220.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 21 20:25 luna.minkagroup.net20121221.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 24 20:26 luna.minkagroup.net20121224.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 25 20:24 luna.minkagroup.net20121225.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 26 20:24 luna.minkagroup.net20121226.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 27 20:23 luna.minkagroup.net20121227.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 28 20:23 luna.minkagroup.net20121228.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 31 20:27 luna.minkagroup.net20121231.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Jan  1 20:25 luna.minkagroup.net20130101.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Jan  2 20:24 luna.minkagroup.net20130102.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Jan  3 20:23 luna.minkagroup.net20130103.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Jan  4 20:22 luna.minkagroup.net20130104.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Jan  7 20:24 luna.minkagroup.net20130107.tar.gz
-rw-rwxr--+ 1 root      root      24711580946 Sep 13 19:21 lunaPre5.2.4Patch.tar.bz
drwxrwx---+ 2 nfsnobody nfsnobody        4096 Oct 12 12:28 oracle
[root@titan luna]# pwd
/u2/backup/luna
[root@titan luna]#


Is my script better workable?

# old scripts from last time
# rm -rf $(find /u2/backup/luna/ -maxdepth 1 -mtime $delDays|sed '1 d' |grep luna.minkagroup.net)
# New script from Jason
find /u2/backup/luna -maxdepth 1 -name "*luna.minkagroup*" -mtime $delDays|xargs rm -f
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 166 total points
ID: 38757580
My mistake, I meant to write
find /u1/backupdisk/ -maxdepth 1 -name "*backup*" -mtime $delDays|sed 1d|xargs rm -f

Open in new window

0
 
LVL 20

Accepted Solution

by:
netcmh earned 251 total points
ID: 38759583
You can always test the script without the delete function

so remove the rm -rf and the () brackets and see if the output matches the resultset you want deleted and then add them back in.

So, try

find /u2/backup/luna/ -maxdepth 1 -mtime $delDays|sed '1 d' |grep luna.minkagroup.net

then add in the rm -rf ()

rm -rf (find /u2/backup/luna/ -maxdepth 1 -mtime $delDays|sed '1 d' |grep luna.minkagroup.net)
0
 

Author Comment

by:Jason Yu
ID: 38759810
when i run this command, it doesn't give me any result:

find /u1/nfsbackup -maxdepth 1 -mtime 10|sed '1 d' |grep luna.minkagroup.net



/u1/nfsbackup is a mounted partition from another server, i use number 10 to replace $delDays globe var.

Very interesting thing is, if I list the directory /u1/nfsbackup, it doesn't show anything either.

I am guessing this folder was not mounted. Am I right?

[root@luna nfsbackup]# cat /etc/fstab
/dev/OS/root            /                       ext3    defaults        1 1
/dev/OS/tmp             /tmp                    ext3    defaults        1 2
/dev/OS/usr             /usr                    ext3    defaults        1 2
/dev/OS/var             /var                    ext3    defaults        1 2
/dev/GIS/LogVol00       /u1                     ext3    defaults        1 2
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   size=3g         0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=SWAP-sda6         swap                    swap    defaults        0 0
titanbk:/u2/backup/luna /u1/nfsbackup           nfs     _netdev,noauto 0 0
titanbk:/u2/backup/luna/oracle /u1/oracle/backup nfs    _netdev,noauto 0 0
[root@luna nfsbackup]# find /u2/backup/luna/ -maxdepth 1 -mtime $delDays|sed '1 d' |grep luna.minkagroup.net
find: missing argument to `-mtime'
[root@luna nfsbackup]# find /u2/backup/luna/ -maxdepth 1 -mtime 10|sed '1 d' |grep luna.minkagroup.net
find: /u2/backup: No such file or directory
[root@luna nfsbackup]# find /u1/nfsbackup -maxdepth 1 -mtime 10|sed '1 d' |grep luna.minkagroup.net
[root@luna nfsbackup]# ls /u1/nfsbackup
[root@luna nfsbackup]#
0
 
LVL 20

Assisted Solution

by:netcmh
netcmh earned 251 total points
ID: 38778628
That would explain why you can't see any results for the command. Check the mount table.
0
 

Author Comment

by:Jason Yu
ID: 38779657
yes, that partition is from a network share, it was not mounted successfully.

This case was resolved, thank you very much.
0
 

Author Closing Comment

by:Jason Yu
ID: 38779659
Good service.
0
 
LVL 20

Expert Comment

by:netcmh
ID: 38783166
Thanks for the grade. Good luck.
0

Featured Post

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

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

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

623 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