(crontab *lib.Crontab)
| 354 | } |
| 355 | |
| 356 | func processCrontab(crontab *lib.Crontab) bool { |
| 357 | defer printLn() |
| 358 | |
| 359 | if !crontab.Exists() { |
| 360 | printWarningText("This crontab does not exist. Skipping.", true) |
| 361 | return false |
| 362 | } |
| 363 | |
| 364 | // This will mostly happen when the crontab is empty |
| 365 | if err, _ := crontab.Parse(noAutoDiscover); err != nil { |
| 366 | printWarningText("This crontab is empty. Skipping.", true) |
| 367 | log(fmt.Sprintf("Skipping %s: %s", crontab.DisplayName(), err.Error())) |
| 368 | return false |
| 369 | } |
| 370 | |
| 371 | // Before going further, ensure we aren't going to run into permissions problems writing the crontab later |
| 372 | if !crontab.IsWritable() { |
| 373 | printWarningText(fmt.Sprintf("This crontab is not writeable. Re-run command with sudo. Skipping"), true) |
| 374 | return false |
| 375 | } |
| 376 | |
| 377 | // If a timezone env var is set in the crontab it takes precedence over system tz |
| 378 | if crontab.TimezoneLocationName != nil { |
| 379 | timezone = *crontab.TimezoneLocationName |
| 380 | } else { |
| 381 | timezone = effectiveTimezoneLocationName() |
| 382 | } |
| 383 | |
| 384 | // This is done entirely so we can print a summary line with a count of cron jobs found in this crontab |
| 385 | if !isAutoDiscover { |
| 386 | count := 0 |
| 387 | for _, line := range crontab.Lines { |
| 388 | if line.IsMonitorable() && !line.IsAutoDiscoverCommand() { |
| 389 | count++ |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | label := "jobs" |
| 394 | if count == 1 { |
| 395 | label = "job" |
| 396 | } |
| 397 | printSuccessText(fmt.Sprintf("Found %d %s in %s", count, label, crontab.DisplayName()), true) |
| 398 | } |
| 399 | |
| 400 | // Read crontab into map of Monitor structs |
| 401 | monitors := map[string]*lib.Monitor{} |
| 402 | allNameCandidates := map[string]bool{} |
| 403 | userExited := false |
| 404 | |
| 405 | for _, line := range crontab.Lines { |
| 406 | if !line.IsMonitorable() { |
| 407 | continue |
| 408 | } |
| 409 | |
| 410 | // Automatically skip jobs marked with "# cronitor: ignore" |
| 411 | if line.Ignored { |
| 412 | continue |
| 413 | } |
no test coverage detected