Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I run this mail command from the terminal, there's no problems:

mail -s "Test Mail" user@example.com < home/user/example.txt

When I add it to a bash script that mainly does this, there's no problems:

tmpString=$(ssh user@server `perl -s` < /home/user/perlscript.pl 2> errorfile.txt)
mail -s "Test Mail" user@example.com < home/user/example.txt

But, when I create a crontab to run the bash script, the mail never gets sent:

10 14 * * * /home/user/mybashscript 

However, I do recieve an email from cronjob about the output. The email with the subject "Test Mail" never arrives.

Anyone had this issue before?

The trace:

Ok, I'll just change some of personal related naming. The mail should be sent before the last echo, but it's not showing up in the trace?

+ . /home/user/.bashrc
++ PS1=`\u@\h \w$`
++ TERM=vt100
++PATH=/usr/sbin:/usr/bin:/bin
++ ssh user@example `perl -s`
+ scriptString=`$VAR` = ``\``Build was OK`\``;`
+echo `$VAR1`= ``\``Build was OK`\``;`
$VAR1 = `Build was OK`;
+ [[ $VAR1 = `Build was OK`; == *\B\u\i\l\d\ \f\a\i\l\e\d* ]]
+ echo

Thanks!

share|improve this question

migrated from stackoverflow.com Oct 19 '12 at 13:10

This question came from our site for professional and enthusiast programmers.

    
What are the permissions of a file? Were you able to add another cron job with another bash file that i.e simply echoes in a file to make sure that your cron job can be executed? –  pankar Oct 19 '12 at 11:59
    
When the cron jub runs, I recieve an email from it with what i echoed, so I think it runs OK. –  user1758367 Oct 19 '12 at 12:35

1 Answer 1

crontab don't have the same environment as yours, so in the top of your script, after the shebang, put :

. ~/.bashrc || . /etc/profile

this will set PATH for child process.

Moreover, modify the shebang to #!/bin/bash -x to turn debug ON, and in your crontab do this :

* * * * * /path/to/script >/tmp/trace 2>&1

and come again with the debug trace.

share|improve this answer
    
Thanks for your reply. I tried adding the line, but the mail still isn't being sent. –  user1758367 Oct 19 '12 at 12:12
    
See my edited post after Moreover –  sputnick Oct 19 '12 at 12:15
    
Ok, I'll just change some of personal related naming. The mail should be sent before the last echo, but it's not showing up in the trace? + . /home/user/.bashrc ++ PS1=\u@\h \w$ ++ TERM=vt100 ++PATH=/usr/sbin:/usr/bin:/bin ++ssh user@example perl -s + scriptString=$VAR = \Build was OK`;` +echo $VAR1= \Build was OK`;` $VAR1 = Build was OK; + [[ $VAR1 = Build was OK; == \B\u\i\l\d\ \f\a\i\l\e\d ]] + echo –  user1758367 Oct 19 '12 at 12:28
    
Please, paste it in your post or on pastebin.com –  sputnick Oct 19 '12 at 12:30
    
Ok, I edited my first post –  user1758367 Oct 19 '12 at 12:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.