Sponsored Content
Full Discussion: yesterday date month/date
Top Forums Shell Programming and Scripting yesterday date month/date Post 302208509 by ripat on Tuesday 24th of June 2008 04:55:12 AM
Old 06-24-2008
If you don't have GNU date, try this in bash:

Code:
TODAY_D=$(date -u +%d)
TODAY_M=$(date -u +%m)
LAST_DAY_OF_M=(-- 31 28 31 30 31 30 31 31 30 31 30 31)
if [[ $TODAY_D == "01" ]];then
        if [[ $TODAY_M == "01" ]];then
                PREVIOUS_M="12"
        else
                PREVIOUS_M=$((TODAY_M-1))
        fi
        printf "%02d/%s" $PREVIOUS_M ${LAST_DAY_OF_M[$PREVIOUS_M]}
else
        printf "%s/%s" $TODAY_M $((TODAY_D-1))
fi
exit 0


Last edited by ripat; 06-24-2008 at 06:39 AM.. Reason: Forgot to take care of January!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare date from db2 table to yesterday's Unix system date

I am currently running the following Korn shell script which works fine: #!/usr/bin/ksh count=`db2 -x "select count(*) from schema.tablename"` echo "count" I would like to add a "where" clause to the 2nd line that would allow me to get a record count of all the records from schema.tablename... (9 Replies)
Discussion started by: sasaliasim
9 Replies

2. Shell Programming and Scripting

Get yesterday's date in year-month-day format?

Dear All, Actually, i'm doing some reporting job and i need to pass yesterday's date in Year-Month-Day format(e.g. 2009-06-10) to another program for generating 2009-06-10 report. to get today's date, it's easy to just date '+%Y%m%d' , but no idea how can i get this kind of format for... (2 Replies)
Discussion started by: tiger2000
2 Replies

3. Shell Programming and Scripting

Pass the first date and last date of previous month

Hi All, I need to run a job every month at the beginning of the month which is scheduled through autosys, lets say on 03/01/2010. I need to pass the last month's i.e February's first_date = 02/01/2010 and last_date = 02/28/2010 as variables to a stored procedure. Can somebody please pass... (2 Replies)
Discussion started by: vigdmab
2 Replies

4. Shell Programming and Scripting

Need help in Shell Script comparing todays date with Yesterday date from Sysdate

Hi, I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing. The above requirement i want in Shell script(KSH)... Can any one please help me? Double post, continued here. (0 Replies)
Discussion started by: kumarmsk1331
0 Replies

5. Shell Programming and Scripting

[Solved] Replace yesterday date with today's date except from the first line

Hello, I have a file like this: 2012112920121130 12345620121130msABowwiqiq 34477420121129amABamauee e7748420121130ehABeheheei in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use... (3 Replies)
Discussion started by: Lilu_CK
3 Replies

6. Shell Programming and Scripting

How to get tomorrow,yesterday date from date Command

Hi I want to get tomorrow and yesterday date from date command. My shell is KSH and server is AIX. I tried several options, but unable to do. Please help on this. Regards Rajesh (5 Replies)
Discussion started by: rajeshmepco
5 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

How to append date to filename, but base it on yesterday's date?

Hello, I'd like to write a monthly archive script that archives some logs. But I'd like to do it based on yesterday's date. In other words, I'd like to schedule the script to run on the 1st day of each month, but have the archive filename include the previous month instead. Here's what I... (5 Replies)
Discussion started by: nbsparks
5 Replies

9. Shell Programming and Scripting

Shell script to compare two files of todays date and yesterday's date

hi all, How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies

10. UNIX for Beginners Questions & Answers

How bash treats literal date value and retrieve year, month and date?

Hi, I am trying to add few (say 3 days) to sysdate using - date -d '+ 3 days' +%y%m%d and it works as expected. But how to add few (say 3 days) to a literal date value and how bash treats a literal value as a date. Can we say just like in ORACLE TO_DATE that my given literal date value... (2 Replies)
Discussion started by: pointers1234
2 Replies
ACCOUNTING(1)                                                         SMPPPD                                                         ACCOUNTING(1)

NAME
accounting - calculates statistics about your internet connections DESCRIPTION
accounting is a simple program to calculate statistics about your internet dial-up connections that are started and stopped by either ifup and ifdown or by a frontend to smpppd like cinternet , qinternet or kinternet. OPTIONS
These options are recognized by accounting. If a long option shows an argument as mandatory, then it is mandatory for the equivalent short option also. -l, --last=NUM Only consider the last NUM connections. -a, --after=DATE Only consider connections started after DATE. DATE is a date with optional time in ISO 8601 format, e.g. `2002-12-24 20:15:00'. Note that a date without time is treated as if the time is 00:00:00. Hence connections started on the specified date are consid- ered. -b, --before=DATE Only consider connections started before DATE. -u, --user=USER Only consider connections started by user USER. --this-year Only consider connections started this year. --last-year Only consider connections started last year. --this-month Only consider connections started this month. --last-month Only consider connections started last month. --this-week Only consider connections started this week. --last-week Only consider connections started last week. --today Only consider connections started today. --yesterday Only consider connections started yesterday. --per-year Show summaries on a per year basis. --per-month Show summaries on a per month basis. --per-week Show summaries on a per week basis. --per-day Show summaries on a per day basis. -c, --connections Only list the connections but do not show provider statistics. -p, --providers Do not list the connections only show the provider statistics. --connection-format=FORMAT The names of the columns to print in the connection list. The names must be separated by a comma. Known column names are time, type, provider, user, status, duration, rx, tx, rxtx, averx, avetx and averxtx. Each name may be appended by a colon and a number indicating the width for the column, e.g. provider:25. The value will not be truncated if the width is too small. --provider-format=FORMAT The names of the columns to print in the provider list equivalent to the --connection-format option. Known column names are provider, number, duration, rx, tx, rxtx, aveduration, averx, avetx and averxtx. --local Display all dates in local time. Also interpret dates on the command line in local time. This is the default. --utc Display all dates in UTC. Also interpret dates on the command line in UTC. --script[=STYLE] Format output for script. Known styles are c and sh. -f, --file=NAME Use a different file with accounting information. --report-errors Report erros in the accounting file. --version Show program version and exit. --help Show help information and exit. NOTES
All informations are only obtained through the accounting log. Hence the informations, esp. the data volume, of currently active connec- tions is not accurate. If you want the know the status of a connection, use ifstatus or a frontend to smpppd like cinternet , qinternet or kinternet instead. The user field is empty for connections started by a remote frontend of smpppd. BUGS
Not yet implemented for ISDN (ippp). FILES
/var/log/smpppd/accounting.log File containing accounting information. SEE ALSO
kinternet, qinternet, cinternet(1), smpppd(8), smpppd-ifcfg(8). AUTHOR
Arvin Schnell <arvin@suse.de> SuSE December 2002 ACCOUNTING(1)
All times are GMT -4. The time now is 06:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy