Sponsored Content
Top Forums Shell Programming and Scripting How to copy the previous month files using shell script? Post 303027878 by venkat918 on Thursday 27th of December 2018 09:15:38 AM
Old 12-27-2018
Thanks all, had applied the below logic to get the last month file.
Code:
#!/bin/bash

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

cd /home/idcuser/venkat/pdf_dir

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

if [[ "$dt" -lt '7' ]]
then
cd /home/venkat/bills/${yr}/${prev_month}
find . -type f -name "*.pdf" -mtime -7 -exec cp "{}" /home/idcuser/fiberbysky/pdf_dir/ \;
fi

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

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


Last edited by venkat918; 12-27-2018 at 10:23 AM..
 

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
CHEWMAIL(1)						User Contributed Perl Documentation					       CHEWMAIL(1)

NAME
chewmail - mail archiver SYNOPSIS
chewmail [OPTIONS] <MAILBOX> ... DESCRIPTION
chewmail is a program for archiving mail. It is inspired by the by the Python-based archivemail, but with more useful semantics. All mail is archived to the mailbox specified with the --output-box switch, in mbox format. It can read mailboxes in mbox, Maildir and MH formats. Internally, chewmail uses Mail::Box, so it support file names and URLs supported by that module. OPTIONS
-o mailbox-format, --output-box=mailbox-format The mailbox to archive messages to. The mailbox is run through the Date::Format module, so it supports all it's conversion specifiers. The date and time is relative to the messages timestamp, or the current time if the timestamp is impossible to determine. A sample of the conversion specifiers follows: %% PERCENT %b month abbr %B month %d numeric day of the month, with leading zeros (eg 01..31) %e numeric day of the month, without leading zeros (eg 1..31) %D MM/DD/YY %G GPS week number (weeks since January 6, 1980) %h month abbr %H hour, 24 hour clock, leading 0's) %I hour, 12 hour clock, leading 0's) %j day of the year %k hour %l hour, 12 hour clock %L month number, starting with 1 %m month number, starting with 01 %n NEWLINE %o ornate day of month -- "1st", "2nd", "25th", etc. %t TAB %U week number, Sunday as first day of week %w day of the week, numerically, Sunday == 0 %W week number, Monday as first day of week %x date format: 11/19/94 %y year (2 digits) %Y year (4 digits) -d days-old, --days=days-old Only archive messages older than than this many days. -D date, --date=date Only archive messages old than this date. The date can be any date understood by Perl's Date::Parse module. -R, --only-read Only archive messages that are marked seen or read. --delete-immediately Synchonize the mailboxes after every message is moved. This will be substantially slower but may provide better recovery for some mail- box formats in the event of a crash. --preserve-timestamp Preserve the atime and mtime of the input mailbox. This only affects file-based mailboxes, such as mbox. -n, --dry-run Go through all the motions of archiving the mail, but don't actually change any mailboxes. -v, --verbose Output more informational messages. Use multiple times for more verbosity. -q, --quiet Don't output any messages other than error messages. -V, --version Print the version number then exit. -h, --help Print usage information then exit. EXAMPLES
Archive two day old messages in inbox to inbox-old: chewmail --days 2 -o inbox-old inbox Archive read messages to a mailbox named the year-month of the message: chewmail --only-read -o %Y-%m inbox SEE ALSO
archivemail(1), Date::Parse, Date::Format, Mail::Box AUTHOR
Eric Dorland <eric@kuroneko.ca> perl v5.8.8 2006-08-15 CHEWMAIL(1)
All times are GMT -4. The time now is 07:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy