User Tools

Site Tools


troubleshooting:cronstoppedworkingonmacbook

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
troubleshooting:cronstoppedworkingonmacbook [2023/02/25 16:42] kamaradskitroubleshooting:cronstoppedworkingonmacbook [2023/03/07 22:51] (current) – [final thoughts] kamaradski
Line 16: Line 16:
 yes, as expected once for root, and once for the local user: yes, as expected once for root, and once for the local user:
 <code bash> <code bash>
-ps aux | grep cron+ps aux | grep cron
 root               457   0.0  0.0 408113488   1056   ??  Ss   Tue06PM   0:00.51 /usr/sbin/cron root               457   0.0  0.0 408113488   1056   ??  Ss   Tue06PM   0:00.51 /usr/sbin/cron
 kamaradski       37314   0.0  0.0 408628368   1632 s013  S+    5:17PM   0:00.00 grep cron kamaradski       37314   0.0  0.0 408628368   1632 s013  S+    5:17PM   0:00.00 grep cron
Line 25: Line 25:
 no: no:
 <code bash> <code bash>
-cat /var/log/system.log | grep "cron"+cat /var/log/system.log | grep "cron"
 </code> </code>
 However, this is not a good thing as i would expect also a note when crons are getting executed successfully However, this is not a good thing as i would expect also a note when crons are getting executed successfully
  
 ===== do we have valid crons? ===== ===== do we have valid crons? =====
 +
 <code bash> <code bash>
-crontab -l+crontab -l
 0 6 * * * cd /Users/kamaradski/00-automation/script1 && go run main.go 0 6 * * * cd /Users/kamaradski/00-automation/script1 && go run main.go
 5 6 * * * cd /Users/kamaradski/00-automation/script2 && go run main.go 5 6 * * * cd /Users/kamaradski/00-automation/script2 && go run main.go
 +</code>
 +
 +Can we run the command from our current user? => yes:
 +
 +<code bash>
 +$ cd /Users/kamaradski/00-automation/script1 && go run main.go
 +12345689%                                                                                                                                                                               
 </code> </code>
  
Line 39: Line 47:
  
 <code bash> <code bash>
-which go+which go
 /opt/homebrew/bin/go /opt/homebrew/bin/go
  
-crontab -e+crontab -e
 crontab: installing new crontab crontab: installing new crontab
  
-crontab -l+crontab -l
 0 6 * * * cd /Users/kamaradski/00-automation/script1 && /opt/homebrew/bin/go run main.go 0 6 * * * cd /Users/kamaradski/00-automation/script1 && /opt/homebrew/bin/go run main.go
 5 6 * * * cd /Users/kamaradski/00-automation/script2 && /opt/homebrew/bin/go run main.go 5 6 * * * cd /Users/kamaradski/00-automation/script2 && /opt/homebrew/bin/go run main.go
 </code> </code>
  
-Lets see tomorrow if this has fixed the issue or not.+And yay what do you know: this fixed my issue :) 
 + 
 +===== have a look at the file permissions ===== 
 + 
 +> By default, the /usr/lib/cron/tabs/ directory should have a file mode of 755 and an owner of root. The files in the directory should have a file mode of 644 and an owner of root. This means that only the root user can modify the files, but any user on the system can view the contents of the files. 
 + 
 +<code bash> 
 +$ ls -l /usr/sbin/cron 
 +-rwxr-xr-x 1 root wheel 205440 Jan 11 08:03 /usr/sbin/cron 
 + 
 +sudo ls -l /usr/lib/cron/tabs 
 +Password: 
 +total 8 
 +-rw-------@ 1 root  wheel  420 Feb 25 17:40 kamaradski 
 +</code> 
 + 
 +This is fine, my particular issue was already fixed in the previous step, however, if your issue is still happening you can always try edit this file to 644 and test again. 
 + 
 +===== why is cron behaving differently? ===== 
 + 
 +The cron daemon runs in the background of a system and executes scheduled tasks based on a predefined schedule. These tasks are executed in a separate environment, which is not the same as the environment of the actual user who is logged in. 
 + 
 +When a user logs into a system, they are assigned a shell, which defines their environment variables, such as PATH, HOME, and others. These environment variables are specific to the user's session and are not shared with other users or processes running on the system. 
 + 
 +In contrast, the environment in which cron jobs run is defined by the cron daemon itself. The cron daemon sets its own environment variables, which are different from those of the user who is logged in. This means that the cron jobs may not have access to the same resources or settings as the user who is logged in, such as environment variables or configuration files. 
 + 
 +Therefore, it's essential to consider the environment in which cron jobs run when scheduling tasks. It's also important to ensure that the necessary environment variables and resources are available to the cron jobs to ensure that they execute correctly. This can include setting the appropriate environment variables within the cron job itself or modifying the system's configuration to ensure that the necessary resources are available to the cron jobs. 
 + 
 +So obviously things like the below will not work: 
 +  * Any EnvVar you have set under your user environment via for example ''.bash_profile'' or ''.bashrc'' 
 +  * Use of standard variables like ''$HOME'' 
 +  * $PATH is also empty, so this is why I needed to specify the full path for the Go application in the example above 
troubleshooting/cronstoppedworkingonmacbook.1677343330.txt.gz · Last modified: 2023/02/25 16:42 by kamaradski