1

I set up a cronjob to write a webpage every 50 minutes, but when accessing them, the webpages were blank.

The cronjob: 50 * * * * mkIndex.sh > /home/user/img/index.html.

The mkIndex.sh is a script I wrote, in /home/$USER/bin, which is in the $PATH, running the script in the same way shown in crontab seems to work fine, it generates the webpage.

So why is my index.html file blank? Alternatively, can you see any flaw in my script?

#!/bin/bash
echo -e "<!DOCTYPE html>\n<head>\n"
echo -e "<style>\ndiv.gallery {\nmargin: 1px;\nborder: 1px solid #ccc;\nfloat: left;\n"
echo -e" width: 180px;\n}\n\ndiv.gallery:hover {\nborder: 1px solid #777;\n}\n\ndiv.gallery img {\n"
echo -e "width: 10%;\nheight: auto;\n}\n"
echo -e "</style>\n</head>\n"
echo -e "<body>\n"
 
cd /home/user/img
for i in `ls *.png`
do
echo -e "<div class="gallery">"
echo -e  "<a target="$i" href="$i">"
echo -e   " <img src="$i"  width="300" height="200">"
echo -e  "</a>"
echo -e "</div>"
done
 
echo -e "</body>\n</html>"

I'm not sure why my cronjob isn't generating the desired output.

j0h
  • 15,365

1 Answers1

0

I added a link to the script in /bin where root can use it. That alone did not work, after editing ctrontab -e every way I could imagine, I deleted my entry there, and edited the file /etc/crontab to include a line for the script with root as the user.
50 * * * * root mkIndex.sh > /home/user/img/index.html

That worked.

j0h
  • 15,365