Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org By way of thanks for all the help.
 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

 08-03-2010, 04:26 AM #1 SilversleevesX Member   Registered: May 2009 Posts: 181 Blog Entries: 9 Rep: 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) #<>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
 08-03-2010, 06:34 AM #2 acid_kewpie Moderator   Registered: Jun 2001 Location: UK Distribution: Gentoo, RHEL, Fedora, Centos Posts: 43,417 Rep: 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.

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