So I need to create a script that writes in a file details about phone calls. The file needs to contain: -CALLING_NUMBER -> which starts with 0742, 0743 and 0744, the rest of the digits being randomly generated ( 10 in total )
-CALLED_NUMBER -> which starts with 07 and the rest of the digits also random
-START_DATE -> the start date of the phone call, in format yyyy-mm-dd hh24:mm:ss. For all phone calls, the start date needs to be from the same day and cover all the hours in that day
-END_DATE -> the end date of the phone call, in the same format, greater than the start date, randomly generating the extra seconds between 0-7200
-CALL_TYPE -> if the duration of the call is 1 sec, it return SMS, if it is longer, it returns VOICE
I did the CALLING_NUMBER and the CALLED_NUMBER and the CALL_TYPE is pretty straight forward once you have end and start date. I am having troubles with the start and end date.
GNU bash,version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Thanks!
This will generate a random
start_dateanchored on a specific day, and then a randomend_datethat is 0-7200 seconds later than that:Note we use here:
date -d 'some_date' +%sto convertsome_dateto Unix timestamp (seconds since epoch)RANDOMvariable, which returns a random integer in a 15-bit range (0 to 32767) each time it is called/referenced. We can get a 30-bit random integer by combining bits of two 15-bit integers with:RANDOM<<15 | RANDOM.date -d @unix_timestampto convert Unix timestamp back to human-readable date/time+"%F %T"format specifier as a shortcut for theYYYY-mm-dd HH:MM:SSformat