0

I am trying to setup analytics for 2 domains. I used sitespeed.io for that. When I log into my Ubuntu server as root and run the shell script, the output is as I want.

But when I run it as a crontab, the command is not executed. The working directory it picks up is /root which is not correct as the docker-compose.yml file is located in the /home/administrator/ directory.

I am unable to figure out which part of the shell script is the reason for that.

Shell script:

dir=$PWD
cd /home/administrator/ && echo $dir
(cd /home/administrator/ && docker-compose run sitespeed.io https://example.com/ --graphite.host=graphite)
(cd /home/administrator/ && docker-compose run sitespeed.io https://example2.com/ --graphite.host=graphite)

Crontab code

*/10 * * * * /home/administrator/dataload.sh >> /home/administrator/dataload.log

Log file contains only /root

systemctl status cron gives the following.

Oct 31 09:50:01 ubuntu40new CRON[20119]: pam_unix(cron:session): session opened for user root by (uid=0)
Oct 31 09:50:01 ubuntu40new CRON[20120]: (root) CMD (/home/administrator/dataload.sh >> /home/administrator/dataload.log)
Oct 31 09:50:01 ubuntu40new CRON[20119]: (CRON) info (No MTA installed, discarding output)
Oct 31 09:50:01 ubuntu40new CRON[20119]: pam_unix(cron:session): session closed for user root

The commands in shell script are not getting executed.

Aman Khandelwal
  • 148
  • 1
  • 13
  • The crontab that is running is probably the crontab for the root user, rather than the administrator user. Check this out - https://stackoverflow.com/questions/8475694/how-to-specify-in-crontab-by-what-user-to-run-script - , set the crontab for the administrator user and see if anything changes. – GregHNZ Oct 31 '19 at 05:24
  • the shell script I have runs only when logged in as root user. – Aman Khandelwal Oct 31 '19 at 05:27

1 Answers1

0

Try installing a mail service

sudo apt-get install postfix
Sanil Khurana
  • 1,129
  • 9
  • 20