LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   By way of thanks for all the help. (https://www.linuxquestions.org/questions/programming-9/by-way-of-thanks-for-all-the-help-823754/)

 SilversleevesX 08-03-2010 05:26 AM

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

 acid_kewpie 08-03-2010 07:34 AM

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.

 All times are GMT -5. The time now is 10:57 PM.