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
createhomedir(1)					    BSD General Commands Manual 					  createhomedir(1)

NAME
createhomedir -- create and populate home directories on the local computer. SYNOPSIS
createhomedir [-scbalh] [-n directoryDomainName] [-u username] DESCRIPTION
createhomedir provides several options for creating and populating home directories. OPTIONS
-s creates home directories for server home paths only (default). -c creates home directories for local home paths only. -b creates home directories for both server and local home paths. -a creates home directories for users defined in all directory domains of the server's search path. -l creates home directories for users defined in the local directory domain. -n directoryDomainName creates home directories for users defined in a specific directory domain in the server's search path. -u username creates a home directory for a specific user defined in the domain(s) identified in the -a, -l, or -n parameter. If you omit the -a, -l, and -n parameters when you use the -u parameter, -a is assumed. -i reads username list from standard input and creates specified home directories. Each username should be on its own line. -h usage help. FILES
/usr/sbin/createhomedir location of tool CAVEATS
When using the -a option, search limits of various directory servers (such as Open Directory or Active Directory) can prevent all possible home directories from being created. In this case, you may need to specify the usernames explicitly. Mac OS X June 1, 2019 Mac OS X
All times are GMT -4. The time now is 08:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy