0

I have a HTML-Form where the user inputs a time (HH:mm).

What I want to do is that this time is used to create a cronjob on the system that deletes a file. The file is always the same. The only thing that can change is the given time from the user.

I am using JavaScript (NodeJS Server), no PHP.

Wulthan
  • 337
  • 2
  • 5
  • 16
  • What have you achieved so far? – Stefano Zanini Mar 14 '17 at 08:49
  • @StefanoZanini I'm have the data from the form created in a .json file. Aim is to read this file which has the line "showUntil: HH:mm". At this given time the cronjob should delete this file. So far I haven't found anything on how to create cronjobs with javascript – Wulthan Mar 14 '17 at 08:52
  • Have you seen this? https://github.com/kelektiv/node-cron – Stefano Zanini Mar 14 '17 at 08:55
  • @StefanoZanini This did it for me, thanks! If you could post it as an answer I can accept it – Wulthan Mar 14 '17 at 11:08

2 Answers2

0

You can see this question to execute commands over server with NodeJS, Execute a command line binary with Node.js

To convert the time in HH:mm to crontab in linux only split in ":" and apply to the crontab with the next format:

* * * HH mm Function....

The next time that the hour pass, your crontab will execute. Remember remove this crontab when don't it's necesary or every day at the same time, the crontab trigger the function.

Regards

Community
  • 1
  • 1
iweb
  • 3
  • 2
0

As per my comment, you can use an external NodeJS library to interact with cron, like node-cron , which will also provide some nice extra features (extended interval syntax, callbacks...).

Stefano Zanini
  • 5,588
  • 2
  • 10
  • 31