LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Closed Thread
 
Search this Thread
Old 08-03-2010, 05:26 AM   #1
SilversleevesX
Member
 
Registered: May 2009
Posts: 181
Blog Entries: 9

Rep: Reputation: 15
By way of thanks for all the help.


A script to generate random dates. It uses the year range 2006-2009, and truncates every month of the year to an ordinary February's 28 days, but otherwise it's pretty solid and safe.

Code:
spate=1
while [ $spate -le 120 ]
do
NUMBER=$[ ( $RANDOM % 864000 ) + 1 ]
RNUMBER=$((RANDOM%4+2006))
ERNUMB=$((RANDOM%11+1))
SHTMON=$[ ($RANDOM%27) + 1 ]
if [ ${#SHTMON} = 1 ]; then day=$(echo "0"$SHTMON); else day=$SHTMON; fi
if [ ${#ERNUMB} = 1 ]; then mon=$(echo "0"$ERNUMB); else mon=$ERNUMB; fi
if [ ${#RNUMBER} = 1 ]; then year=$(echo "0"$RNUMBER); else year=$RNUMBER; fi
b=$[NUMBER / 60]
c=$[b * 60]
seconds=$[NUMBER-c]
d=$[b / 60]
e=$[d * 60]
minutes=$[b-e]
hours=$[e/60] 

#Padding single-length time entries with zeros
if [ ${#seconds} = 1 ]; then sec=$(echo "0"$seconds); else sec=$seconds; fi
if [ ${#minutes} = 1 ]; then min=$(echo "0"$minutes); else min=$minutes; fi
if [ ${#hours} = 1 ]; then hrs=$(echo "0"$hours); else hrs=$hours; fi
longtime=$(echo $hrs$min.$sec) #<< the random time in 'touch -t'-friendly format (seconds marked off by a period, not a colon).
deatt=$(echo $year$mon$day) #<< Setting date in 'touch -t' format
time=$(echo $deatt$longtime) #<<Putting the date and time together, keeping the formats (no spaces)
echo "$time">>randomtime.txt
echo "Written - random date number $spate."
spate=$[spate+1]
done
YMMV, but when I used the following script on a folder of 120 JPEG files, no two dates were the same. The times? I'm not positive they were likewise all unique, but at a glance I didn't see much repetition.
Code:
while read 'line';
do
nardo=$(echo $line)
chachi=$(echo $nardo | cut -d, -f2)
joanie=$(echo $nardo | cut -d, -f1)
richie=$(basename "$joanie")
echo "Working on file $richie now."
touch -t $chachi $joanie

done<timetemp
And to think this was going to be the topic of a question, me looking for help yet again! Four hours of Google-ing, cross-referencing online MAN and Info pages, and coming across near-to-topic and spot-on threads in forums such as LQ and Unix-Linux Forums (www.unix.com), and such as that gave me just enough where I could turn it around and make this offering.

Again, thanks.

BZT

Last edited by SilversleevesX; 08-03-2010 at 05:31 AM.
 
Old 08-03-2010, 07:34 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.
 
  


Closed Thread

Tags
bash, date, file, random, time, touch


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT -5. The time now is 08:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration