Sponsored Content
Top Forums Shell Programming and Scripting Moving log files based on month - help with ksh shell script Post 302595522 by chihung on Friday 3rd of February 2012 10:54:10 AM
Old 02-03-2012
see 'man ls' under the --time-style. you can use the +FORMAT to specify the time format you like. In your case, it wiil be --time-style=+%b

Code:
cd /test/logs
mkdir Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
ls -l --time-style=+%b | while read perm size user group byte month filename
do
  if [ -f "$filename" ]; then
    mv "$filename" $month
  fi
done

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help with shell script for moving/deleting/renaming files

Hi. I need help with a little script that will be used to move some files to their parent directory, delete the directory, rename one file in the parent directory and delete another, then continue to the next. Here's an example: /var/media/Music/Genesis/1970 album - Trespass (2008 Box -... (4 Replies)
Discussion started by: aflower
4 Replies

2. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

3. Shell Programming and Scripting

How to extract log info based on last month?

Hi Gurus I'm using HPUX B.11.23 ia64, the below sample log data was extracted from HPUX commnad: last -R. Sample data: root pts/ta userpc Wed Aug 11 09:46 - 20:21 (10:35) root pts/ta userpc Wed Aug 11 09:44 - 20:10 (10:34) root pts/ta userpc Wed Aug 11... (4 Replies)
Discussion started by: superHonda123
4 Replies

4. Shell Programming and Scripting

Need help to write a script for moving the log files to some other folder

Hi Experts, I want to write a script, based upon the following requirement 1) I am having 5 application $ cd logs $ ls -l drwxr-xr-x 2 natraj nat 5.0K Sep 20 10:25 one drwxr-xr-x 2 natraj nat 5.0K Sep 20 10:39 two drwxr-xr-x 2 natraj nat 1.5K Sep 20 10:58... (4 Replies)
Discussion started by: natraj005
4 Replies

5. Solaris

Move files into different folders based on its month

Hi All, I want to move the files in to different folders based on the files month in the file timestamp. For example All the september files in the directory should moves into the folder "sep_bkp_files" , August files in to aug_bkp_files folder... Please help me to achive the above... (10 Replies)
Discussion started by: velava
10 Replies

6. UNIX for Dummies Questions & Answers

Script moving files based on date

Hi, I need a script that moves files based on date to a folder. The folder should be created based on file date. Example is : Date file name ----- -------- Oct 08 07:39 10112012_073952.xls Oct 09 07:39 10112012_073952.xls Oct 10 07:39 ... (6 Replies)
Discussion started by: rockingvj
6 Replies

7. Shell Programming and Scripting

Fetch files based on month

Hi All I have a requirement like below.I have always 12 files got generated in my directory called /xx/out/ abc_2014_10_121.xml abc_2014_09_345.xml abc_2014_08_432.xml abc_2014_07_123.xml abc_2014_06_098.xml abc_2014_05_569.xml abc_2014_04_430.xml abc_2014_03_235.xml abc_2014_02_056.xml... (9 Replies)
Discussion started by: chigurupati.dwh
9 Replies

8. UNIX for Dummies Questions & Answers

Need script to move files based on month

Hi , I need a script which moves files based on month. Example : Apr 29 03:16 log4.txt Apr 29 03:16 log5.txt May 4 09:17 log1.txt May 4 09:17 log2.txt Move Apr files into Apr2015(Folder) Move May files into May2015(Folder). This is urgent requirement , if you can help me... (5 Replies)
Discussion started by: rockingvj
5 Replies

9. Shell Programming and Scripting

Shell Script for renaming and moving Files - Easy?

Hey guys, ive been working on this for about 2hrs now - without any solution. At first I need to say I dont have skills in linux bash scripting, but I tried to use some codesnippets and manuals from google. What I want to do: I have different folders including 2 different filestypes with... (15 Replies)
Discussion started by: peter1337
15 Replies

10. Shell Programming and Scripting

How to copy the previous month files using shell script?

could you please assist the below query. i had written the below piece of code to copy the files from one directory to another. For current month files had been copied ,unfortunately the previous month files not copied. Please find the below directory structure:- ls -lrt total 1824... (2 Replies)
Discussion started by: venkat918
2 Replies
JDMONTHNAME(3)								 1							    JDMONTHNAME(3)

jdmonthname - Returns a month name

SYNOPSIS
string jdmonthname (int $julianday, int $mode) DESCRIPTION
Returns a string containing a month name. $mode tells this function which calendar to convert the Julian Day Count to, and what type of month names are to be returned. Calendar modes +-----+--------------------------------------+---+ |Mode | | | | | | | | | Meaning | | | | | | | | Values | | | | | | +-----+--------------------------------------+---+ | 0 | | | | | | | | | Gregorian - abbreviated | | | | | | | | Jan, Feb, Mar, Apr, May, Jun, Jul, | | | | Aug, Sep, Oct, Nov, Dec | | | | | | | 1 | | | | | | | | | Gregorian | | | | | | | | January, February, March, April, | | | | May, June, July, August, September, | | | | October, November, December | | | | | | | 2 | | | | | | | | | Julian - abbreviated | | | | | | | | Jan, Feb, Mar, Apr, May, Jun, Jul, | | | | Aug, Sep, Oct, Nov, Dec | | | | | | | 3 | | | | | | | | | Julian | | | | | | | | January, February, March, April, | | | | May, June, July, August, September, | | | | October, November, December | | | | | | | 4 | | | | | | | | | Jewish | | | | | | | | Tishri, Heshvan, Kislev, Tevet, She- | | | | vat, AdarI, AdarII, Nisan, Iyyar, | | | | Sivan, Tammuz, Av, Elul | | | | | | | 5 | | | | | | | | | French Republican | | | | | | | | Vendemiaire, Brumaire, Frimaire, | | | | Nivose, Pluviose, Ventose, Germinal, | | | | Floreal, Prairial, Messidor, Thermi- | | | | dor, Fructidor, Extra | | | | | | +-----+--------------------------------------+---+ PARAMETERS
o $jday - The Julian Day to operate on o $calendar - The calendar to take the month name from RETURN VALUES
The month name for the given Julian Day and $calendar. PHP Documentation Group JDMONTHNAME(3)
All times are GMT -4. The time now is 02:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy