2017-08-20 24 views
-1
#Assume i have ubuntu, selenium and chrome driver in the image 

ADD crontab /etc/cron.d/simple-cron 
# Add crontab file in the cron directory 
ADD crontab /etc/cron.d/simple-cron 

# Add shell script and grant execution rights 

RUN wget myjava.jar [From some central repository] 
RUN chmod +x /myjava.jar 


ADD script.sh /script.sh 
RUN chmod 777 /script.sh 

# Give execution rights on the cron job 
RUN chmod 0644 /etc/cron.d/simple-cron 

# Create the log file to be able to run tail 
RUN touch /var/log/cron.log 


ADD run.sh /run.sh 
RUN chmod +x /run.sh 
CMD ["/run.sh"] 



Crontab: 
* * * * * root /script.sh 

script.sh: 
export DISPLAY=:99 
cd/
/usr/bin/java -jar myjava.jar 

run.sh: 
#!/bin/bash 
Xvfb :99 -screen 0 1024x768x16 & 
cron -f 

我正在使用上面提到的dockerfile,我有一个每分钟运行的cron作业。我没有看到日志在Google云端控制台中被捕获。在GKE中运行cron作业时,没有显示在Google云端控制台中的日志

我看到类似的帖子,讨论类似的问题。但我没有看到解决方案。 Google Container Engine stdout Logs Not Showing Up

我无法将我的cron脚本移动到我的Docker文件中的入口点。 请让我知道如何在运行cron作业时将日志重定向到谷歌云控制台。

回答

1

我遇到了同样的问题,无法找到一种方法让cron输出任何东西。作为解决方法,您可以将> /proc/1/fd/1添加到crontab条目中,并且脚本的输出将被记录。例如:

* * * * * root /script.sh >/proc/1/fd/1 2>&1 
+0

你的意思是我的crontab条目应该是这样的crontab: * * * * *根/script.sh&>的/ proc/1/FD/1 – bigdata

+0

是的,但如果你”重新使用'sh'你可能需要使用'* * * * * root /script.sh>/proc/1/fd/1 2>&1' – morloch

+0

非常感谢。我在GKE日志记录控制台中看到日志。 – bigdata