mgeneratejs icon indicating copy to clipboard operation
mgeneratejs copied to clipboard

execution from cron throws `SyntaxError: Unexpected end of JSON input`

Open fullaware opened this issue 6 years ago • 1 comments

I'm executing mgeneratejs via cron and receive SyntaxError: Unexpected end of JSON input. This does not happen if I execute the script directly:

mgenerate.sh script contents

mgeneratejs '{"name": "$name", "age": "$age", "emails": {"$array": {"of": "$email", "number": 3}}}' -n 50 | mongoimport --port 27018 -d customers -c contacts

When executed manually I get the following results and the data is successfully imported:

$ /data/UPLOAD/mgenerate.sh
2018-11-19T10:47:27.878-0500	connected to: localhost:27018
2018-11-19T10:47:28.672-0500	imported 50 documents

However when executed via cron I see the following error in mail and no documents are imported:

2018-11-19T10:45:01.577-0500	connected to: localhost:27018
undefined:1

SyntaxError: Unexpected end of JSON input
    at Object.parse (native)
    at Socket.<anonymous> (/usr/lib/node_modules/mgeneratejs/bin/mgenerate.js:94:21)
    at emitNone (events.js:91:20)
    at Socket.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:978:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
2018-11-19T10:45:02.304-0500	imported 0 documents

I've installed globally npm install -g mgeneratejs for both my user as well as root.

While I do miss having this GREAT tool in Python:mtools, its still the best tool out there! Great work guys!

fullaware avatar Nov 19 '18 15:11 fullaware

Hi, sorry for the delayed response. I'm not quite sure how I can help with this. We'd need to better understand what the cron job is doing differently. Did you ever figure out what the problem was?

"While I do miss having this GREAT tool in Python:mtools, its still the best tool out there! Great work guys!"

I just felt it didn't really fit into the mtools collection as mgeneratejs doesn't deal with log files or launching mongodb instances. The Javascript version is also faster and has more features due to chance.js and faker.js.

rueckstiess avatar Nov 28 '18 02:11 rueckstiess