![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Getting yesterday DATE | osymad | Shell Programming and Scripting | 19 | 09-23-2009 03:39 PM |
| Help, I need to get the last date of previous month | sirrtuan | Shell Programming and Scripting | 11 | 10-14-2008 06:59 AM |
| last month end date | vanathi | UNIX for Advanced & Expert Users | 7 | 03-21-2008 04:17 PM |
| How to show yesterday date | wind_n_cloud | Shell Programming and Scripting | 1 | 02-16-2005 10:51 PM |
| get yesterday date in yyyymmdd format | hk_newbie | UNIX for Dummies Questions & Answers | 2 | 12-14-2001 03:32 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
yesterday date month/date
Hi expert,
I want to retrieve yesterday su log. How to calculate and assign variable value ( 06/23 ) in myVariable ? #!/bin/sh myVariable=yesterday date in month/date cat /var/adm/sulog | grep $myVariable > file.txt many thanks! |
|
||||
|
I don't think I have that. How to check ?
I can extract the date , let say 24. But how to do -1 How to correct below code's syntax in /bin/sh myDate= `date -u +%d` myMonth=`date -u +%m` myYear=`date -u +%Y` myAnotherMonth=`date -u +%b` if [ $myDate == 1 && ( $myAnotherMonth == Sep || $myAnotherMonth == Apr || $myAnotherMonth == Jun || $myAnotherMonth == Nov || $myAnotherMonth == Feb ) ] then yesterday = 30 elseif [ $myDate == 1 && $myAnotherMonth == Feb] yesterday=28 # I dont worry about month end with 29 else yesterday = $myDate - 1 fi cat /var/adm/sulog | grep "$myMonth\/$yesterday" | grep -v grep > $myYear$myMonth$yesterday_sulog.txt Last edited by skully; 06-24-2008 at 04:28 AM.. |
|
||||
|
To know your version of date, just run my command and see what your box reply. A workaround, but again with GNU date: Code:
#!/bin/bash STAMP_TODAY=$(date --utc --date "$1" +%s) STAMP_YESTERDAY=$((STAMP_TODAY-86400)) DTE_YESTERDAY=$(date --utc --date "1970-01-01 $STAMP_YESTERDAY sec" "+%m/%d") echo $DTE_YESTERDAY |
|
||||
|
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! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|