crontab.lua 732 B

123456789101112131415161718192021222324252627
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Copyright 2008-2013 Jo-Philipp Wich <jow@openwrt.org>
  3. -- Licensed to the public under the Apache License 2.0.
  4. local fs = require "nixio.fs"
  5. local cronfile = "/etc/crontabs/root"
  6. f = SimpleForm("crontab", translate("Scheduled Tasks"), translate("This is the system crontab in which scheduled tasks can be defined."))
  7. t = f:field(TextValue, "crons")
  8. t.rmempty = true
  9. t.rows = 10
  10. function t.cfgvalue()
  11. return fs.readfile(cronfile) or ""
  12. end
  13. function f.handle(self, state, data)
  14. if state == FORM_VALID then
  15. if data.crons then
  16. fs.writefile(cronfile, data.crons:gsub("\r\n", "\n"))
  17. luci.sys.call("/usr/bin/crontab %q" % cronfile)
  18. end
  19. end
  20. return true
  21. end
  22. return f