Sponsored Content
Top Forums UNIX for Beginners Questions & Answers File Size Split up based on Month Post 303010983 by drysdalk on Thursday 11th of January 2018 10:18:04 AM
Old 01-11-2018
Hi,

OK, thanks, I think I get what you're needing. Try something like this:

Code:
#!/bin/bash

if [ "$1" == "" ]
then
        echo "You must provide a month and year, e.g.:"
        echo "Jan-2017, Aug-2015, etc"
        exit 1
else
        date="$1"
fi

if [ "$2" == "" ]
then
        echo "You must provide a directory to generate a report for, e.g.:"
        echo "/home/unixforum/276398"
        exit 1
else
        reportroot="$2"
fi

if ! [ -d "$reportroot" ]
then
        echo "Your specified report root does not exist, try again."
        exit 1
fi


echo "Disc usage within "$reportroot" for "$date":"

for directory in `/usr/bin/find "$reportroot" -mindepth 1 -maxdepth 1 -type d -newermt "01-$date -1 sec" -and -not -newermt "01-$date +1 month -1 sec" -print`
do
        /usr/bin/du -sb "$directory"
done

Here's a sample session of it being run with identical directories to those provided in your example.

Code:
$ ls -l
total 32
drwxr-xr-x 2 unixforum users 4096 May  1  2017 AAA/
drwxr-xr-x 2 unixforum users 4096 May 12  2017 BBB/
drwxr-xr-x 2 unixforum users 4096 Aug  1 00:00 CCC/
drwxr-xr-x 2 unixforum users 4096 Aug 12 00:00 DDD/
drwxr-xr-x 2 unixforum users 4096 Jul 16 00:00 XXX/
drwxr-xr-x 2 unixforum users 4096 Jul 13  2017 YYY/
drwxr-xr-x 2 unixforum users 4096 Sep 12 00:00 ZZZ/
-rwx------ 1 unixforum users  663 Jan 11 15:13 report.sh*
$ ./report.sh May-2017 /home/unixforum/276398
Disc usage within /home/unixforum/276398 for May-2017:
4096    /home/unixforum/276398/BBB
4096    /home/unixforum/276398/AAA
$ ./report.sh Aug-2017 /home/unixforum/276398
Disc usage within /home/unixforum/276398 for Aug-2017:
4096    /home/unixforum/276398/CCC
4096    /home/unixforum/276398/DDD
$ ./report.sh Jul-2017 /home/unixforum/276398
Disc usage within /home/unixforum/276398 for Jul-2017:
4096    /home/unixforum/276398/XXX
4096    /home/unixforum/276398/YYY
$ ./report.sh Sep-2017 /home/unixforum/276398
Disc usage within /home/unixforum/276398 for Sep-2017:
4096    /home/unixforum/276398/ZZZ
$

So basically as long as you provide the month and year as MMM-YYYY, and the full path to the directory the report is to be generated for, then you'll be fine. If that directory never changes you could hard-code these as variables and do away with having to provide them, but this makes it as interactive as possible as it currently stands.

Hope this helps.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split a large file with patterns and size

Hi, I have a large file with a repeating pattern in it. Now i want the file split into the block of patterns with a specified no. of lines in each file. i.e. The file is like 1... 2... 2... 3... 1... 2... 3... 1... 2... 2... 2... 2... 2... 3... where 1 is the start of the block... (5 Replies)
Discussion started by: sudhamacs
5 Replies

2. UNIX for Dummies Questions & Answers

split files based on size

I have a few txt files in some directory and I need to check their sizes one by one. If any of them are greater than 5mb then I need to split the file in two. Can someone help? Thanks. (6 Replies)
Discussion started by: khanvader
6 Replies

3. Shell Programming and Scripting

Split file based on size

Hi Friends, Below is my requirement. I have a file with the below structure. 0001A1.... 0001B1.. .... 0001L1 0002A1 0002B1 ...... 0002L1 .. the first 4 characters are the sequence numbers for a record, A record will start with A1 and end with L1 with same sequence number. Now the... (2 Replies)
Discussion started by: diva_thilak
2 Replies

4. Shell Programming and Scripting

Split a file based on pattern and size

Hello, I have a large file (2GB) that I would like to split based on pattern and size. I've used the following command to split the file (token is "HELLO") awk '/HELLO/{i++}{print > "file"i}' input.txt and the output is similar to the following (i included filesize in KB): 10 ... (2 Replies)
Discussion started by: jl487
2 Replies

5. Shell Programming and Scripting

Split file based on file size in Korn script

I need to split a file if it is over 2GB in size (or any size), preferably split on the lines. I have figured out how to get the file size using awk, and I can split the file based on the number of lines (which I got with wc -l) but I can't figure out how to connect them together in the script. ... (6 Replies)
Discussion started by: ssemple2000
6 Replies

6. Shell Programming and Scripting

Split the file based on column

Hi, I have a file sample_1.txt (300k rows) which has data like below: * Also each record is around 64k bytes 11|1|abc|102553|125589|64k bytes of data 10|2|def|123452|123356|...... 13|2|geh|144351|121123|... 25|4|fgh|165250|118890|.. 14|1|abc|186149|116657|......... (6 Replies)
Discussion started by: sol_nov
6 Replies

7. Shell Programming and Scripting

Split the file based on pattern

Hi , I have huge files around 400 mb, which has clob data and have diffeent scenarios: I am trying to pass scenario number as parameter and and get required modified file based on the scenario number and criteria. Scenario 1: file name : scenario_1.txt ... (2 Replies)
Discussion started by: sol_nov
2 Replies

8. UNIX for Dummies Questions & Answers

Split file based on column

i have file1.txt asdas|csada|130310|0423|A1|canberra sdasd|sfdsf|130426|2328|A1|sydney Expected output : on eaceh third and fourth colum, split into each two characters asdas|csada|13|03|10|04|23|A1|canberra sdasd|sfdsf|13|04|26|23|28|A1|sydney (10 Replies)
Discussion started by: radius
10 Replies

9. Shell Programming and Scripting

Split the File based on Size

I have a file that is about 7 GB in size. The requirement is I should split the file equally in such a way that the size of the split files is less than 2Gb. If the file is less than 2gb, than nothing needs to be done. ( need to done using shell script) Thanks, (4 Replies)
Discussion started by: rudoraj
4 Replies

10. Shell Programming and Scripting

To Split the file based on column value

Hi Team, I have a requirement in such a way that need to split the file into two based on which column particular value appears.Please find my sample file below. Lets consider the delimiter of this file as either comma or two colons.(:: and ,). So I need to split the file in such a way that all... (2 Replies)
Discussion started by: ginrkf
2 Replies
UNBURDEN-HOME-DIR(1)						   User Commands					      UNBURDEN-HOME-DIR(1)

NAME
unburden-home-dir - unburdens home directories from caches and trashes SYNOPSIS
unburden-home-dir [ -n | -u | -f filter ] unburden-home-dir ( -h | --help | --version ) DESCRIPTION
unburden-home-dir unburdens the home directory from files and directory which cause high I/O or disk usage but are neither important if they are lost, e.g. caches or trash directory. When being run it moves the files and directories given in the configuration file to a location outside the home directory, e.g. /tmp or /scratch, and puts appropriate symbolic links in the home directory instead. OPTIONS
-f just unburden those directory matched by the given filter (a perl regular expression) -- matches the already unburdened directories if used together with -u. -F Do not check for files in use with lsof before (re)moving files. -n dry run (show what would be done) -u undo (reverse the functionality and put stuff back into the home directory) -h, --help show this help --version show the program's version EXAMPLES
Example configuration files can be found at /usr/share/doc/unburden-home-dir/examples on Debian-based systems and in the etc/ directory of the source tar ball. FILES
/etc/unburden-home-dir, /etc/unburden-home-dir.list, ~/.unburden-home-dir, ~/.unburden-home-dir.list, /etc/default/unburden-home-dir, /etc/X11/Xsession.d/95unburden-home-dir Read /usr/share/doc/unburden-home-dir/README on debianoid installations or README in the source tar ball for an explanation of these files. SEE ALSO
corekeeper (http://openvswitch.org/cgi-bin/gitweb.cgi?p=corekeeper), autotrash(1), agedu(1), bleachbit(1). For du(1)-like but more comfortable tools, see ncdu(1) (text-mode), baobab(1) (GNOME), filelight(1) (KDE), xdiskusage(1) (X tool calling du(1) itself), or xdu(1) (X tool reading du(1) output from STDIN). AUTHOR
Unburden Home Dir is written and maintained by Axel Beckert <beckert@phys.ethz.ch> LICENSE
Unburden Home Dir is available under the terms of the GNU General Public License (GPL) version 2 or any later version at your option. Unburden Home Directory May 2012 UNBURDEN-HOME-DIR(1)
All times are GMT -4. The time now is 10:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy