Solved Script does not run as expected in crontab

Hi Guys,
I have a short script that runs squid analyzer and mails me a simple confirmation that it ran ok. Just for fun I added a python script that draws a little graphic. All works fine when I run it manually, but when I run it as a cron job it doesn't draw the graphic. I've tried adding a wait 10 seconds after executing the python script but it doesn't make any difference. Like I said, It's just for fun and not important, but I would like to know what I might be doing wrong?
Here's the script:-

Code:
#!bin/bash
{
echo
cd /usr/local/bin/
squid-analyzer
echo
python /home/ahounsome/bin/progressbar.py 10 50
echo
echo "squid-analyzer reports generated ok"
echo "click here to access reports http://tinman/squidreport"
} | mail -s "squid-analyzer reports generated ok on tinman" andyhounsome@gmail.$

Code:
and here's the output from the generated email when run manually:-
[                                                  ] 0%
[=====                                             ] 10%
[==========                                        ] 20%
[===============                                   ] 30%
[====================                              ] 40%
[=========================                         ] 50%
[==============================                    ] 60%
[===================================               ] 70%
[========================================          ] 80%
[=============================================     ] 90%
[==================================================] 100%

squid-analyzer reports generated ok
click here to access reports http://tinman/squidreport

and here's what I get when I run it as a cron job:-

Code:
squid-analyzer reports generated ok
click here to access reports http://tinman/squidreport
 
Many thanks for your advice and patience. I tried replacing the incorrect shebang with
#!/bin/sh. This didn’t make any difference, so I did as wblock@ suggested and removed the line completely. Unfortunately this didn't help either, so I'm still stuck. Also, as wblock@ suggested I didn't need the { } I removed them. But this caused an error as detailed below:-

Code:
squid-analyzer-reports.sh: 8: Syntax error: "|" unexpected

Any help would be gratefully appreciated.

 
Last edited by a moderator:
...
Any help would be gratefully appreciated.
wblock@ posted a link. Please look at topic #2 of that link, and try to understand the meaning of "Use full paths." In addition you might want to submit the following commands:
which squid-analyzer
which python
which mail

This would show you said paths.
 
so I did as wblock suggested and removed the line completely. Unfortunately this didn't help either, so I'm still stuck. Also, as wblock suggested I didn't need the {} I removed them.
Actually, that was not what I was suggesting. To expand on the original:

That script does not need any bash-specific features. So use sh(1) and #!/bin/sh.

sh(1) uses parentheses for subshells. So the { and } are replaced with ( and ).
 
Hi Guys,
thank you so much for all your help. I've taken your comments on board and revised my script accordingly. So it now reads as follows:-

Code:
#!/bin/sh
echo
/usr/local/bin/python /home/ahounsome/bin/progressbar.py 10 50
#sh(1)
(
uuencode /home/ahounsome/bin/tinman.png /home/ahounsome/tmp/tin-man.png
cd /usr/local/bin/
squid-analyzer
echo
/usr/local/bin/python /home/ahounsome/bin/progressbar.py 10 50
echo
echo "squid-analyzer reports generated ok"
echo "click here to access reports http://tinman/squidreport"
uuencode /home/ahounsome/bin/squidlogo.png /home/ahounsome/tmp/squid-logo.png
) | mail -s "squid-analyzer reports generated ok on tinman" andyhounsome@gmail.com

As you can see I've added a few images as well, just for fun and it's now working fine.
Thanks again to all of you that have made comments and generally helped me out.
Please mark this as solved.
 
andyh2451, I've marked the thread solved but you can do that yourself in the future as well by clicking on "Thread Tools" then "Edit Thread" at the top right of the page while viewing the thread. :)
 
But if you use full paths, it is less likely a compromised binary with the same name elsewhere in the path can be run. The full paths can be defined once and then used numerous times.
Code:
LS="/bin/ls"
${LS}
 
Back
Top