- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: get date of last week with script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-10-2010 09:37 PM
тАО05-10-2010 09:37 PM
i'm mading a script
i want to get all date of last week with script.
today is 05/04/2010
Begin date will be Mon - 04/26/2010
Tue - 04/27/2010
Wed - 04/28/2010
Thu - 04/29/2010
Fri - 04/30/2010
Sat - 05/01/2010
End date will be Sun - 05/02/2010
how can i make a script.
help me
Thanks
Solved! Go to Solution.
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-10-2010 09:59 PM
тАО05-10-2010 09:59 PM
Re: get date of last week with script
then minus 7 days, then convert the result back to normal date/time
Gudluck
Prasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-10-2010 10:10 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-10-2010 10:36 PM
тАО05-10-2010 10:36 PM
Re: get date of last week with script
Thank you very much.......
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-10-2010 11:02 PM
тАО05-10-2010 11:02 PM
Re: get date of last week with script
I don't wanted the last seven days from today
i wanted all date of last week.
Get date => monday~Sunday of last week.
Please help me.
Good luck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-10-2010 11:10 PM
тАО05-10-2010 11:10 PM
Re: get date of last week with script
Current_time_epoch=`perl -e "print time "`
Week_day=`date +%a`
#days to be minus to get last sunday
# IF today is
# Sunday = 7days
# monday = 8days
# teusday= 9days
# Wednesday= 10days
# Thursday= 11days
# friday= 12days
# saturday= 13days
case "$Week_day" in
Sun ) Sec_to_last_sunday=` echo 7 | awk '{print $1*24*60*60}'` ;;
Mon ) Sec_to_last_sunday=` echo 8 | awk '{print $1*24*60*60}'` ;;
Tue ) Sec_to_last_sunday=` echo 9 | awk '{print $1*24*60*60}'` ;;
Wed ) Sec_to_last_sunday=` echo 10 | awk '{print $1*24*60*60}'` ;;
Thu ) Sec_to_last_sunday=` echo 11 | awk '{print $1*24*60*60}'` ;;
Fri ) Sec_to_last_sunday=` echo 12 | awk '{print $1*24*60*60}'` ;;
Sat ) Sec_to_last_sunday=` echo 13 | awk '{print $1*24*60*60}'` ;;
esac
let "Last_Sunday_epoch = $Current_time_epoch - $Sec_to_last_sunday"
let "Last_Mon_epoch = $Last_Sunday_epoch + 86400"
let "Last_Tue_epoch = $Last_Mon_epoch + 86400"
let "Last_Wed_epoch = $Last_Tue_epoch + 86400"
let "Last_Thu_epoch = $Last_Wed_epoch + 86400"
let "Last_Fri_epoch = $Last_Thu_epoch + 86400"
let "Last_Sat_epoch = $Last_Fri_epoch + 86400"
############Create a tmplate script ######
echo '#!/usr/bin/perl
$time = localtime($ARGV[0]);
print "$time\n";
' > /tmp/epoch_to_normal.pl
chmod 755 /tmp/epoch_to_normal.pl
#############################################
/tmp/epoch_to_normal.pl $Last_Sunday_epoch
/tmp/epoch_to_normal.pl $Last_Mon_epoch
/tmp/epoch_to_normal.pl $Last_Tue_epoch
/tmp/epoch_to_normal.pl $Last_Wed_epoch
/tmp/epoch_to_normal.pl $Last_Thu_epoch
/tmp/epoch_to_normal.pl $Last_Fri_epoch
/tmp/epoch_to_normal.pl $Last_Sat_epoch
Try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-10-2010 11:11 PM
тАО05-10-2010 11:11 PM
Re: get date of last week with script
your expected output is like this ????
[root@vm1 ~]# ./get_last_week_days.sh
Sun May 2 08:34:10 2010
Mon May 3 08:34:10 2010
Tue May 4 08:34:10 2010
Wed May 5 08:34:10 2010
Thu May 6 08:34:10 2010
Fri May 7 08:34:10 2010
Sat May 8 08:34:10 2010
Gudluck
Prasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-10-2010 11:39 PM
тАО05-10-2010 11:39 PM
Re: get date of last week with script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-11-2010 05:37 AM
тАО05-11-2010 05:37 AM
Re: get date of last week with script
...or all in Perl:
# perl -le '$t=time();$d=7+(localtime)[6];$b=$t-($d*86400);for (0..6) {print scalar localtime($b+($_*86400))}'
Sun May 2 09:34:33 2010
Mon May 3 09:34:33 2010
Tue May 4 09:34:33 2010
Wed May 5 09:34:33 2010
Thu May 6 09:34:33 2010
Fri May 7 09:34:33 2010
Sat May 8 09:34:33 2010
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-11-2010 05:46 PM
тАО05-11-2010 05:46 PM
Re: get date of last week with script
i have a question.
i don't know perl script.
i want to change date format as below:
Mon May 3 10:42:43 2010 => 20100503
Please help me.
Thanks