Convert every date to epoch timestamp text/JSON - bash

I'm receiving some JSON files through a git repo I need to feed into a database.
Is there any command line script/utility so I can convert every date in the json fields from ISO 8601 (example: 2014-11-18T23:00:00.000Z) to its timestamp/unix epoch equivalent?

This is what I used to go from timestamp to ISODate, hope you find this helpful to get what you want.
/usr/bin/mongo mydb --eval
"db.collection.find().forEach(function(doc){
doc.timestamp = new ISODate(new Date(doc.timestamp).toISOString());
db.collection.save(doc)
});"
Also, use this. Good luck!

Related

Convert epoch time format in jmeter

We are able to see a Timestamp column upon splitting the JTL file generated after a load test.
We want to convert the Timestamp (Which is currently in epoch format) to a more understandable and readable format such as dd/mm/yyyy hh:mm:ss.
Please help us.
Copy these properties from jmeter.properties file and add to user.properties file
#---------------------------------------------------------------------------
# Results file configuration
#---------------------------------------------------------------------------
# Timestamp format - this only affects CSV output files
# legitimate values: none, ms, or a format suitable for SimpleDateFormat
jmeter.save.saveservice.timestamp_format=ms
jmeter.save.saveservice.timestamp_format=yyyy/MM/dd HH:mm:ss.SSS
just comment or uncomment the line jmeter.save.saveservice.timestamp_format=yyyy/MM/dd HH:mm:ss.SSS for getting epoch time or human readable timestamp format.
Need to restart the jmeter after updating the user.properties file

Downloading Only Newest File Using Wget / Curl

How would I use wget or curl to download the newest file in a directory?
This seems really easy, however the filename won't always be predictable, and as new data comes in it'll be replaced with a random filename.
Specifically, the directory I wish to download data from has the following naming structure, where the last string of characters is a randomly generated timestamp:
MRMS_RotationTrackML1440min_00.50_20160530-175837.grib2.gz
MRMS_RotationTrackML1440min_00.50_20160530-182639.grib2.gz
MRMS_RotationTrackML1440min_00.50_20160530-185637.grib2.gz
The randomly generated timestamp is in the format of: {hour}{minute}{second}
The directory in question is here: http://mrms.ncep.noaa.gov/data/2D/RotationTrackML1440min/
Could it have to be something with something in the headers, where you'd use curl to sift through the last-modified timestamp?
Any help would be appreciated here, thanks in advance.
You can just run following command periodically:
wget -r -nc --level=1 http://mrms.ncep.noaa.gov/data/2D/RotationTrackML1440min/
It will download recursively whatever is new in the directory after last run.

How to resolve date format returned by FTP file listing commands?

I am using an FTP server which, while listing the files using e.g. ls command, returns the last modification date in following format:
05/06/12
Is there a way to know what date format the remote server is using?
There is no definition about date format in the listings, it is not even defined that the listings should include the date at all. So you can only guess if you need to parse the listing. For a reliable and defined way to get the modification time of a file use the MDTM command. Unfortunately you need to send this for each file which could make everything slower.

How to update a program with a daily changing file name?

I have a program that reads in a file and does some parsing to it. The file is generated by another program every night. Due to the ICD the date is part of the file name.
The file name changes every night due to the date change so I am not sure how to have my program change the fileIn name to accommodate this.
If the current fileIn is:
in20120103out.dat
Tomorrow's fileIn is:
in20120104out.dat
filename = Time.now.strftime("in%Y%m%dout.dat")
or
require 'date'
filename = Date.today.strftime("in%Y%m%dout.dat")
strftime means string format for time. The %-parameters are placeholder for Year (Y), month (m), day (d). (There are more placeholders, e.g. year without century...)
You can use the strftime() method to generate the date portion of the filename:
t = Time.­now
filename = "in#{t.strftime('%Y%m%d')}out.dat"
And then use the filename variable to open the file as normal.

Compress a file with todays date

I want to compress a file with name ASCOnnect200_V5.0.0.0_09_Dec_11.zip. I it possible with winrar/rar?
The file name ASCOnnect200_V5.0.0.0_ will be always constant and the date part will be in the format dd-mmm-yy.
In cmd:
rar.exe a -ag+YYYYMMDD arc {FolderName}
The answer is in this forum :)

Resources