Sponsored Content
Top Forums Shell Programming and Scripting find command with complex logic Post 302387092 by MaureenT on Thursday 14th of January 2010 01:48:46 PM
Old 01-14-2010
find with complex logic

So the ideal would be to keep the last 2 build#'s so you have the last successful deploy and the current one which may have multiple iterations but as the folder names are constantly changing that would be too difficult, this is an attempt to do the same thing with different logic.

Example 1 - would want to keep the last 2 folders from Dec 22/23
Code:
/Deployments1
drwxr-xr-x   18 wasadm   wasgroup       4096 Dec 11 10:50 2.0.0.020.20091130-1446
drwxr-xr-x   18 wasadm   wasgroup       4096 Jan 05 12:31 2.0.0.020.final.20091207-1048
drwxr-xr-x   18 wasadm   wasgroup       4096 Dec 11 13:07 2.0.0.021.20091210-1236
drwxr-xr-x   19 wasadm   wasgroup       4096 Dec 22 11:41 2.0.0.022.20091217-1126
drwxr-xr-x   18 wasadm   wasgroup       4096 Dec 23 14:49 2.0.0.023.20091223-1155

Example 2 - in this case would keep the last 3 builds because they are within the 2 day criteria (would probably change this to something like a 7 day criteria so would actually be saving the last 4 builds)
Code:
/Deployments2
drwxr-xr-x   17 wasadm   wasgroup       4096 Nov 17 21:52 2.0.0.019.20091117-1929
drwxr-xr-x   18 wasadm   wasgroup       4096 Nov 19 00:50 2.0.0.019.20091118-1742
drwxr-xr-x   20 wasadm   wasgroup       4096 Nov 25 12:59 2.0.0.020.20091124-1656
drwxr-xr-x   18 wasadm   wasgroup       4096 Nov 26 10:49 2.0.0.020.20091125-1748
drwxr-xr-x   18 wasadm   wasgroup       4096 Nov 26 22:24 2.0.0.020.20091126-1150

Even better would be to come up with logic that compared the first part of the folder name and if it is the same keep all those plus 1 more. ie. 2.0.0.020 - keep all that matched this, plus the last 2.0.0.019.
So you would want to save the most recent folder, any folders that match the same first 10 characters of that folder, and then the most recent folder before all of those folders. All other folders would be deleted.

---------- Post updated at 10:48 AM ---------- Previous update was at 09:20 AM ----------

I'm getting closer. This will give me that last build and any associated revisions of it. Now I just have to figure out how to add the last previous folder to this list, and then use this as an exclude list while I delete the other folders.
Code:
ls | tail -1 | cut -c -10 | xargs -i ksh -c "find . -name '{}*'"


Last edited by Scott; 01-14-2010 at 07:14 PM.. Reason: Code tags
 

8 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

advanced/complex uses of the find command

Perhaps the number one advanced find question is: How to stop find from descending into subdirectories? find command Performing a non-recursive find in Unix Use -prune with find command on AIX Searching for files over 30 days old in current directory disk space used for files with in a... (0 Replies)
Discussion started by: Perderabo
0 Replies

2. Shell Programming and Scripting

Complex find grep or sed command

Haven't worked in bash for ages. did a good bit of shell scripting in regular sh, but have forgotten most of it. I have several thousand php files that now include the following line at the end of the file. There is no LF or CR/LF before it begins, it is just concatenated to the final line of... (3 Replies)
Discussion started by: sjburden
3 Replies

3. Shell Programming and Scripting

complex find in script

How to I put my find command string into a script. It is currently to long to be entered manually at command line. for FNAME in `find /unixsxxx/interface/x.x/xxxxxx -type f \( -name '*.KSH' -o -name '*.sh' -o -name '*.sql' -o -name '*.ksh' \) -exec grep -il xxx.xxx.xxx.xxx {} \;`; do C=`grep -c... (5 Replies)
Discussion started by: TimHortons
5 Replies

4. Shell Programming and Scripting

pls help! complex find and replace

help pls... i would like to change this CURVE2 565489 789458 1258649 random data here... CURVE2 565489 568795 6548921 random data here... CURVE2 565489 123598 6446259 random data here... CURVE2 565489 672956 2489657 into this CURVE2 565489 586423 1258649 random data here...... (2 Replies)
Discussion started by: lakanino
2 Replies

5. UNIX for Advanced & Expert Users

complex find command

Hi all, I am trying to execute the following command: find 'path' -ls -exec cksum {} \; As you can see this simply finds files from a given path and runs cksum on them. My problem is this, if i have a FIFO in a directory the find tries to execute cksum on it and gets stuck. From the man page i... (9 Replies)
Discussion started by: noam128
9 Replies

6. UNIX for Advanced & Expert Users

Help with complex find syntax

I need to modify the find command below to exclude the output of the directory /usr/UDPM/PerfMgmt/shmlck find / \( -fstype ctfs -o -fstype mntfs -o -fstype objfs -o -fstype proc -o ! local \) -prune -o -type f -perm -0002 -print 2>/dev/null I have tried many iterations and placement of... (2 Replies)
Discussion started by: interesting?
2 Replies

7. Shell Programming and Scripting

Complex find and replace only 1st instance string with dynamic combination

test.txt is the dynamic file but some of combination are fix like below are the lines ;wonder_off = ;wonder_off = disabled wonder_off = wonder_off = disabled the test.txt can content them in any order #cat test.xt ;wonder_off = ;wonder_off = disabled wonder_off = wonder_off =... (5 Replies)
Discussion started by: SilvesterJ
5 Replies

8. Shell Programming and Scripting

Command Logic

Hi, I need the logic to utilize the command output to be feeded over to successive commands, for example : $ dtconf list-ls-data-sources -h hostname -P 636 -w ~/pwd.txt DATA MASTER 1 DATA MASTER 2 DATA CONSUMER 1 DATA CONSUMER 1 DATA CONSUMER 1 Based on above output, i would like... (7 Replies)
Discussion started by: johnprince1980
7 Replies
folders(1mh)															      folders(1mh)

Name
       folders - list folders and contents

Syntax
       folders [ +folder ] [ msg ] [ options ]

Description
       The command displays the names of your folders and the number of messages that they each contain.

       The  command displays a list of all the folders in your Mail directory.	The folders are sorted alphabetically, each on its own line.  This
       is illustrated in the following example:
	 Folder      # of messages (  range  ); cur  msg  (other files)
	   V2.3  has	3 messages (   1-   3).
	 adrian  has   20 messages (   1-  20); cur=   2.
	  brian  has   16 messages (   1-  16).
	  chris  has   12 messages (   1-  12).
	copylog  has  242 messages (   1- 242); cur= 225.
	  inbox+ has   73 messages (   1- 127); cur= 127.
	    int  has	4 messages (   1-   4); cur=   2  (others).
	   jack  has   17 messages (   1-  17); cur=  17.

		 TOTAL= 387 messages in 8 folders.
       The plus sign (+) after inbox indicates that it is the current folder.  The information about the folder includes the term (others).   This
       indicates  that the folder contains files which are not messages.  These files may be either sub-folders, or files that do not belong under
       the MH file naming scheme.

       The command is identical to the effect of using the -all option to the command.

       If you use with the +folder argument, it will display all the subfolders within the named folder.  as shown in the following example:
       % folders +test
       Folder		# of messages (  range	); cur	msg  (other files)
       test+ has	  18 messages (   1-  18);	     (others).
       test/testone has    1 message  (   1-   1).
       test/testtwo has   no messages.

	      TOTAL=   19 messages in 3 folders.
       See for more details of sub-folders.

Options
       -fast
       -nofast	 Lists only the name of folders, with no additional information.  This is faster because the folders need not be read.

       -help	 Prints a list of the valid options to this command.

       -list
       -nolist	 Lists the contents of the folder-stack.  No +folder argument is allowed with this option.

       -pack
       -nopack	 Re-numbers messages in the folders.  Messages are re-numbered sequentially, and any gaps  in  the  numbering  are  removed.   The
		 default operation is -nopack, which does not change the numbering in the folder.

       -pop	 Discards  the	top of the folder-stack, after setting the current folder to that value.  No +folder argument is allowed with this
		 option.  This corresponds to the operation in the C-shell; see The -push and -pop options are mutually exclusive: the last occur-
		 rence of either one overrides any previous occurrence of the other.

       -push	 Pushes  the  current  folder  onto  the  folder-stack, and makes the +folder argument into the current folder.  If +folder is not
		 given, the current folder and the top of the folder-stack are exchanged.  This corresponds to the operation in the  C-shell;  see
		 The  -push switch and the -pop switch are mutually exclusive: the last occurrence of either one overrides any previous occurrence
		 of the other.

       -recurse
       -norecurse
		 Lists folders recursively.  Information on each folder is displayed, followed by information on any  sub-folders  which  it  con-
		 tains.

       -total
       -nototal  Displays  only the total number of messages and folders in your Mail directory.  This option does not print any information about
		 individual folders.  It can be suppressed using the -nototal option.

       The defaults for are:

	      +folder defaults to all
	      msg defaults to none
	      -nofast
	      -noheader
	      -nototal
	      -nopack
	      -norecurse

Restrictions
       MH does not allow you to have more than 100 folders at any level in your Mail directory.

Profile Components
       Path:		 To determine your MH directory
       Folder-Protect:	 To set protections when creating a new folder
       Folder-Stack:	 To determine the folder stack
       lsproc:		 Program to list the contents of a folder

Files
       The user profile.

See Also
       csh(1), folder(1mh), refile(1mh), mhpath(1mh)

																      folders(1mh)
All times are GMT -4. The time now is 10:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy