go 在crontab里面运行报错 解决方案
问题背景
你高高兴兴的写好了一个go脚本,放到你的服务器上,打算定期运行这个脚本,你打开crontab -e,
然后输入:
*/1 * * * * go run /root/test/main.go
然后发现迟迟没有反应,你就查看一下输出什么错误:
*/1 * * * * go run /root/test/main.go >> /root/test/log.txt
然后报错如下:
build command-line-arguments: cannot load test/mypath: malformed module path "test/mypath": missing dot in first path element
missing dot in first path element ? What ? 你会好奇,你明明使用了:
go mod init test
go mod tidy
然后你测试了一下,如果cd /root/test/,然后run 是非常正常的,
一旦在非/root/test/目录下,就会出现这种路径报错问题,
类似的问题还有:
➜ root go run /Users/thoth/program/gocode/alarm15m/main.go
alarm15m/main.go:12:2: package alarm15m/mypath is not in GOROOT (/usr/local/go/src/alarm15m/mypath)
alarm15m/main.go:13:2: package alarm15m/tools is not in GOROOT (/usr/local/go/src/alarm15m/tools)
Xxx is not in GOROOT , 总是在导包上出问题!
这b玩意,为啥这样,我也不知道,我也不想研究他(每天的学习任务安排很满,我觉得这种就是特定语言特定的场景没必要,通识性知识才是重要的,这种Xxx语言我一天就会切换3~4种,很难每个都去研究,完成任务就好),估计就是有他路径设置的考虑,管他呢,反正有一点确定的就是在项目路径下执行一定是成功的,基于这个很确定的点,我想到一些曲线救国方案。
解决
直接写sh脚本
run.sh
#!/bin/sh
cd /root/test/
go run main.go
crontab -e
*/15 * * * * bash /root/test/run.sh
完美解决。
go 在crontab里面运行报错 解决方案的更多相关文章
- Scrapy运行报错解决方案
最近在学习Scrapy框架,用博客记录一下遇到的错误的解决方案 时间: 2016-9-20 错误:ImportError: No module named items 原因:spiders下的.py文 ...
- Flutter运行报错 `kernel_snapshot for errors` 解决方案
Flutter运行报错 `flutter kernel_snapshot for errors`解决方案 当你Flutter项目删除了dart文件如果遇到 target:kernel_snapshot ...
- appium运行报错java.net.SocketException: socket write error
这个错我调了 快两天一点头绪没有,脚本正常跑没问题,但是就是控制台输出信息报错,没法定位问题在哪.报错如图: 虽然这个报错不影响测试结果,但是本人有强迫症,一定要查出究竟: 我的尝试: 1.那天试验, ...
- Quartz框架调用——运行报错:ThreadPool class not specified
Quartz框架调用——运行报错:ThreadPool class not specified 问题是在于Quartz框架在加载的时候找不到quartz.properties配置文件: 解决方案一: ...
- 转:CentOS上安装LAMP之第三步:MySQL环境及安装过程报错解决方案(纯净系统环境)
这是AMP运行环境中最后配置的环境: 惯例传送门: 1.编译安装MySQL cd /home/zhangatle/tar tar zxvf mysql-.tar.gz cd mysql- cmake ...
- SpringBoot-使用lombok插件运行报错
SpringBoot-使用lombok插件运行报错 标签(空格分隔): java,SpringBoot 1.报错信息 2.解决方案 1.IDEA编辑器安装lombok插件 2.编译注解配置-Enabl ...
- Eclipse开发Android项目报错解决方案详细教程,最新版一篇就够了!
本文记录刚接触Android开发搭建环境后新建工程各种可能的报错,并亲身经历漫长的解决过程(╥╯^╰╥),寻找各种偏方,避免大家采坑,希望能帮助到大家. 报错信息 出错一:The import and ...
- Robotframework学习笔记之—Rrobotframework运行报错“command: pybot.bat --argumentfile”
Rrobotframework运行报错"command: pybot.bat --argumentfile" 解决方案: 1.可能是缺失文件: 1.1.检查python安装目录下的 ...
- macaca运行报错之chrome-driver问题处理,关闭 Chrome 的自动更新
由于chrome浏览器自动更新,导致 macaca运行报错,重新安装和更新chrome-driver 之后,还需要把chrome浏览器降级到50版本: 但是chrome会自动更新,所以需要禁止.找到这 ...
随机推荐
- Codeforces Round #587 (Div. 3) F Wi-Fi(线段树+dp)
题意:给定一个字符串s 现在让你用最小的花费 覆盖所有区间 思路:dp[i]表示前i个全覆盖以后的花费 如果是0 我们只能直接加上当前位置的权值 否则 我们可以区间询问一下最小值 然后更新 #incl ...
- Codeforces Global Round 8 D. AND, OR and square sum(位运算)
题目链接:https://codeforces.com/contest/1368/problem/D 题意 给出一个大小为 $n$ 的数组 $a$,每次可以选两个下标不同的元素,一个赋为二者相与的值, ...
- poj2778 DNA Sequence(AC自动机+矩阵快速幂)
Description It's well known that DNA Sequence is a sequence only contains A, C, T and G, and it's ve ...
- SPOJ 227 Ordering the Soldiers
As you are probably well aware, in Byteland it is always the military officer's main worry to order ...
- hdu3506 Monkey Party
Problem Description Far away from our world, there is a banana forest. And many lovely monkeys live ...
- spring-cloud-netflix-config
Spring Cloud Config 在我们了解spring cloud config之前,我可以想想一个配置中心提供的核心功能应该有什么 提供服务端和客户端支持 集中管理各环境的配置文件 配置文件 ...
- Principle for iOS App Animation Design
Principle for iOS App Animation Design Animate Your Ideas, Design Better Apps https://principleforma ...
- leetcode bug & 9. Palindrome Number
leetcode bug & 9. Palindrome Number bug shit bug "use strict"; /** * * @author xgqfrms ...
- D language
D language https://en.wikipedia.org/wiki/D_(programming_language) Dart https://dlang.org/ flutter fr ...
- html fragment & html template & virtual DOM & web components
html fragment & html template & virtual DOM https://developer.mozilla.org/en-US/docs/Web/API ...