Getting the current Date in Your Scripts
I LIKE stamping things with the date, whether it’s a status report email or filename. (Like say I’ve downloaded todays news in Spanish, it really seems to make sense to tag it as spanish_news_12_8_08.mp3 instead of just spanish_news.mp3 doesn’t it?)
Okay, so this is something I do in a lot of my shell scripts. Here’s some code to play with.
Thankfully, linux has a great (and flexible) date command…
In the top part of your script just assign the variable date as such:
date=`date +%b%d%Y`
this uses the date command with the following format: Dec082008
Of course, there are other ways to format it – like date +%F which gives you 2008-12-08
As you’re seeing the +and then %letter formats the date. There are MANY different ways to format the date, in fact, if you just want the month, or day of week, that’s possible too. you might want to consult the manual page for date to see all the choices.
So… from the console type man date
now, you can have the date or time stamp you want in any of your shell scripts.
Popularity: 1% [?]
Related Posts - Quickbooks "An error has occurred in the script on this page" I ran into an install of Quickboos Pro 2005 that was having a peculiar problem. When any company file was opened I was seeing an Internet Explorer Script Error message (quickbooks uses Internet Explorer to parse the company page ( Usually C:\Program Files\Intuit\Quickbooks\Components\Pages\Comppage.qpg ) The error basically said "An error......
- The security of remote tech support (ultravnc sc or x11vnc with wrapper script) Well, I've got a nice way of doing "easy" one click (or one cut and paste) light desktop support for windows or linux, one uses ultravnc sc, the other uses x11vnc with a special wrapper script. So, what security flaws are there in this process? Well, for starters, I see......
- Remote Tech Support with x11vnc and wrapper script So, the idea is that I wanted something "like" the Ultranvnc Single Click download, only for linux. The main idea being is that if someone is looking for a bit of desktop tech support on linux, we don't need to be giving instructions for 5 different package managers, or source......
Related Websites - Creating a Blog Video Online About two years ago, blogging hit a surge that allowed its way into the mainstream, and now everybody is blogging for a wide variety of different reasons. Blogs resemble web-based public diaries of sorts, where the creator can record their thoughts, their opinions, questions and answers and essentially anything else......
- Learn How To Utilize Whitehat Strategies To Create Backlinks To Your Blog Whitehat off page SEO methods, backlinking, takes a concerted effort on your part so it is done right. You will need to be dedicated to this effort only because it takes much longer and your results will not be so immediate. Learning how to make your own backlinks the whitehat......
- How to Change the Date and Time Format for WordPress Blog By default your WordPress blog will display date and time as "September 3, 2010" and "12:59 am". When using the default template you can easily change the format by changing the General Settings from your WordPress Admin page. Go to Settings > General and change the settings using the button......
Similar Posts
- Recording online streams (real / wma) to mp3 format (or ogg) with mplayer
- Scheduling tasks in linux cron
- Using the command line in linux – part 1
- Converting Audio to PCM Wave format
- Using the command line in linux – part 2