Technology Insights

Echo Cron To Syslog

When creating cron tasks on Linux many people do not realize that the output from the cron will logged and without redirection will sent to the user running the cron task’s email. In many cases this is the root user or if an alias has been set in /etc/aliases then the email will be sent to the user configured to receive roots email in the aliases file. Specifically on Backtrack Linux the root users email is redirected to bt5 by default and that user does not exist so the email will simply bounce. Below we describe a better way to redirect the cron tasks output into a log file which could be useful down the road.

Code Snippets

Bash Script That Deletes Directories Older Than X Days If Y Number Of Directories Exist

Earlier tonight I created a little script that will run in cron on a Linux server. The script counts the number of directories and files in a specific directory and if the count is above Y then it deletes directories and files older than X number of days. In the example script below the number of items (directories and files) that have to be located in the directory before the script to delete files older than a specific date is 10. If there are ten items then the script will delete items older than 90 days. Below the script is the entry made in a specific users cron on the Linux server.

Technology Errors

Cron Bash Script Error: /usr/bin/env: ruby: No such file or directory

I needed to create a bash shell script tonight that called another shell script with options that then would load a Ruby environment and execute certain commands within a Ruby project. I ran into numerous issues but most were silly things such as typos or other minor issues caused by myself. The one issue I had a little trouble figuring out because of the file that was causing the error related to cron not being able to run “/usr/bin/env: ruby”. My bash script worked perfectly from the Linux CLI shell however when attempting to run it I would always get the same error. Below I list details about the error, where I finally located what the error was, and how to resolve the error.