Sponsored Content
Top Forums Shell Programming and Scripting Adding Previous Month To Filename Post 302672185 by kris.adrianto on Monday 16th of July 2012 04:57:56 AM
Old 07-16-2012
Adding Previous Month To Filename

Dear experts,

I'm using solaris 5.10 and bash. I want to zip file "Amount.txt" to "Amount.zip" and rename it to "Amount_<prev_month>_<this year>.zip". For example, file for this month should be renamed to "Amount_06_2012.zip", for next month it should be "Amount_07_2012.zip". I have no problem for zipping the file. Here's the script but it's not working:

Code:
month=`date +%m`
year=`date +%Y`
lmonth=`expr $month - 1`
if test "$lmonth" = "0"
then
lmonth=12
year=`expr $year - 1`
fi

mv Amount.zip Amount_`$lmonth`_`$year`.zip

When I executed it, it shows:
Code:
./script.sh: 6: not found
./script.sh: 2012: not found

Then the zip file renamed to "Amount__.zip"

Best regards,
Kris Adrianto
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

file name using previous month

This has probably been asked 100 times, but I couldn't find any articles on point. I have a script that runs on the last day of every month at 11:30pm. If cats a number of input tables that were created the previous month (or earlier), combines them into one master file and erases the indivual... (1 Reply)
Discussion started by: beilstwh
1 Replies

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

3. Shell Programming and Scripting

last working day of previous month

Hi, I want a script(ksh) to see if today is the last working day(Mon-Fri) of the month. If it is the last working day I need to print current date, else I need the last working day of previous month. Thanks in advance. (1 Reply)
Discussion started by: rspk_praveen
1 Replies

4. Shell Programming and Scripting

Help, I need to get the last date of previous month

Hi, I'm new with Unix, I'm trying to get a last day of previous month with this format: %b %d %Y (example: Feb 25 2008). Here is what I have so far. #!/bin/ksh cur_month=`date +%m` cur_year=`date +%Y` prev_month=$(($cur_month-1)) # Check to see if this is January if then ... (11 Replies)
Discussion started by: sirrtuan
11 Replies

5. UNIX for Dummies Questions & Answers

How to get the previous month by using `date`

Hello, I'm new to shell scripting. We've develop a script which will grep a file on the search criteria, MON (Jan/Feb/Mar/etc). But we should set this sript in cron which will run on every first day of the month. The problem I'm having is, when I run the script, it is displaying the contents of... (7 Replies)
Discussion started by: suneelj
7 Replies

6. Shell Programming and Scripting

Function to get previous month

Can someone help me creating a function which will give me previous months. like for example if the date is 200902 and if i call my function and pass a parameter 2 i want to get 200812 as the answer. or if i pass 200902 with a parameter 7 then my function should give me the date as 200807. (1 Reply)
Discussion started by: Lincy
1 Replies

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

8. UNIX for Dummies Questions & Answers

Get the previous month from date

Hi All, I am using the below code to get the year and month from date: Below gives output like 201212. dt=`date '+%Y%m'` how do i get the previous month value(ie: subtract 1 from date) example output: dt=201211 Please help. :confused: (3 Replies)
Discussion started by: abhi_123
3 Replies

9. 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
fimgs(1)						      General Commands Manual							  fimgs(1)

NAME
fimgs - poor man's [http://]PostScript/pdf/dvi/cbr/rar/cbz/zip viewer for the linux framebuffer console SYNOPSIS
fimgs [ options ] file DESCRIPTION
fimgs is a simple wrapper script which takes a PostScript or pdf or .cbr or .rar or .cbz or .zip or .dvi or any of the above prefixed with http:// as input, renders the pages using ghostscript into a temporarely directory and finally calls fbi to display them. In case of com- pressed archives (in zip or rar formats), the images are decompressed into a directory and displayed. In this latter case, only images contained in the archive will be displayed (no nested archives or pdf's or ps's or dvi's). OPTIONS
fimgs still does not understand all of fim's options (they are not passed through). so please use fimgs -h to get help on its options. You can use option -p <password> if your PDF file requires password. SEE ALSO
fim(1), gs(1), fbi(1), fbgs(1), bash(1) AUTHOR
Michele Martone <dezperado _ GUESS _ autistici.org>. (c) 2007-2009 Michele Martone fimgs(1)
All times are GMT -4. The time now is 01:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy