Sponsored Content
Top Forums Shell Programming and Scripting How to copy the previous month files using shell script? Post 303026873 by venkat918 on Tuesday 4th of December 2018 11:33:49 AM
Old 12-04-2018
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
drwxrwxrwx 2 root root 1839104 Oct 3 17:14 9
drwxrwxrwx 2 root root 20480 Nov 30 02:25 11----Nov month directory structure.
drwxrwxr-x 2 idcuser idcuser 4096 Dec 4 10:28 12---Dec Month directory strucure

using the below srcript, i can copy only the current month files that only four days of files and other files are not copied .Due to other files were in Nov month.

Code:
#!/bin/bash

Day=$(date +%A)
dt=$(date +%d)
yr=$(date +%Y)
mon=$(date +%b)
month=$(date +%m)
Date=$(date +%d_%m_%Y)

cd /home/idcuser/venkat/pdf_dir

find . -type f -exec rm -f {} \;

cd /home/skyline4/bills/${yr}/${month}

find . -type f -name "*.pdf" -mtime -7 -exec cp "{}" /home/idcuser/venkat/pdf_dir/ \;

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get previous month files

Hi, My task to to delete files which are of previous months. I have files named as follows *CCYYMMDD.xls. on a particular day i have delete previous months files i.e in Dec i have delete all nov files which look like 200511DD.XLS in Jan i have to delete all Dec files 200512DD.xls ... (7 Replies)
Discussion started by: savitha
7 Replies

2. Shell Programming and Scripting

How to get the Previous month in Korn Shell

Hi I have a requirement where i have to append the prev month (e.g Feb for current date ) to the file name before sending it for some other processing. if input file name is xyz.txt output for the today's run should be xyz_Feb.txt. i tried this code 1 curmth=`date +%m` 2 mth=(Dec Jan Feb... (1 Reply)
Discussion started by: nvuradi
1 Replies

3. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

4. Shell Programming and Scripting

shell script to search and copy files

Hello Im new to this forums, I would like some help regarding a script that I need in order to copy some files. Heres the scenario: I need to search several files which have a particular code inside, lets say "test" all of them on different directories. I need to copy all of them on a new... (4 Replies)
Discussion started by: c.watson
4 Replies

5. 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

6. Shell Programming and Scripting

Moving log files based on month - help with ksh shell script

Hello, I'm trying to move the log files from the parent directory to respective monthly folder and I would be running this script on a weekly basis through cron. I'm new to this scripting and here is what i could come up and it runs without really doing anything. I even tried placing echo... (2 Replies)
Discussion started by: jusblues
2 Replies

7. Shell Programming and Scripting

Help with getting last date of previous month and first date of previous 4th month from current date

I have requirment to get last date of previous month and the first date of previous 4th month: Example: Current date: 20130320 (yyyymmdd) Last date of previous month: 20130228 (yyyymmdd) First date of previous 4th month: 20121101 (yyyymmdd) In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies

8. Shell Programming and Scripting

Getting the previous month as input for the script

Hi Experts , I have scheduled a script "createstructure "in crontab. The script runs every month on 25th . I am trying to pass the input to the script as the <year><previousmonth>.For example ,if it is running in the month of March 2014 ,the input should be "201402" (2014-year 02-previous... (7 Replies)
Discussion started by: Pradeep_1990
7 Replies

9. Shell Programming and Scripting

Shell script to copy files from on folder to another

I am trying to copy files with specific date and name to another folder. I am very new to shell scripting so i am finding it hard to do that. see the sample code i have written below. srcdir="/media/ubuntu/CA52057F5205720D/Users/st4r8_000/Desktop/office work/26 nov"... (13 Replies)
Discussion started by: Aqeel Abbas
13 Replies

10. Shell Programming and Scripting

To copy files which are created in particular month

Hi GUys, I need to copy the files which are created on particuar month for eg ls dir Jul 12 12:46 apple.txt Jun 16 15:58 file.txt i need to copy only files which are created on current month Please use CODE tags as required by forum rules! (11 Replies)
Discussion started by: Master_Mind
11 Replies
CAL(1)							    BSD General Commands Manual 						    CAL(1)

NAME
cal, ncal -- displays a calendar and the date of easter SYNOPSIS
cal [-jy] [[month] year] cal [-j] -m month [year] ncal [-jJpwy] [-s country_code] [[month] year] ncal [-Jeo] [year] DESCRIPTION
The cal utility displays a simple calendar in traditional format and ncal offers an alternative layout, more options and the date of easter. The new format is a little cramped but it makes a year fit on a 25x80 terminal. If arguments are not specified, the current month is dis- played. The options are as follows: -J Display Julian Calendar, if combined with the -e option, display date of easter according to the Julian Calendar. -e Display date of easter (for western churches). -j Display Julian days (days one-based, numbered from January 1). -m month Display the specified month. -o Display date of orthodox easter (Greek and Russian Orthodox Churches). -p Print the country codes and switching days from Julian to Gregorian Calendar as they are assumed by ncal. The country code as deter- mined from the local environment is marked with an asterisk. -s country_code Assume the switch from Julian to Gregorian Calendar at the date associated with the country_code. If not specified, ncal tries to guess the switch date from the local environment or falls back to September 2, 1752. This was when Great Britain and her colonies switched to the Gregorian Calendar. -w Print the number of the week below each week column. -y Display a calendar for the specified year. A single parameter specifies the year (1 - 9999) to be displayed; note the year must be fully specified: ``cal 89'' will not display a calen- dar for 1989. Two parameters denote the month and year; the month is either a number between 1 and 12, or a full or abbreviated name as specified by the current locale. Month and year default to those of the current system clock and time zone (so ``cal -m 8'' will display a calendar for the month of August in the current year). A year starts on Jan 1. SEE ALSO
calendar(3), strftime(3) HISTORY
A cal command appeared in Version 5 AT&T UNIX. The ncal command appeared in FreeBSD 2.2.6. AUTHORS
The ncal command and manual were written by Wolfgang Helbig <helbig@FreeBSD.org>. BUGS
The assignment of Julian--Gregorian switching dates to country codes is historically naive for many countries. BSD
November 23, 2004 BSD
All times are GMT -4. The time now is 01:41 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy