Debuggging bash cron scripts.

I have to several times debug scripts that I get complain about working when logging in normally but they do not work when run in cron mode. So, quite a lot of times, redirecting the stderr of the script is all that is required to see what is happening, but sometimes that just does not help if the script is calling another script which is mis-behaving and under lot of other conditions. So, how to at-least take a look at why these are failing, login with ssh.

Use the “noprofile” option to ensure that user profile settings are not sourced and you should be good to test. (Do not try to do this with “user#localhost”, as by that time you would have already sourced the profile.)

ssh -t user@server "bash --noprofile"

Now, if you want to run bash like this, then you need a terminal, and thus dont forget the “-t” option as well.

This site uses Akismet to reduce spam. Learn how your comment data is processed.