gpt4 book ai didi

bash - mvn clean 在终端中运行良好,但在 cron 和 bash 文件中运行不正常

转载 作者:行者123 更新时间:2023-11-29 09:13:38 25 4
gpt4 key购买 nike

mvn clean 在终端上运行良好。即使当我通过双击从 bash 文件(.sh 文件)执行相同的操作时,它也能正常工作。

但是当我使用 crontab 触发相同的操作时,我收到错误 mvn:command not found

bash(.sh) 文件有这段代码

#!/bin/bash 
cd /Users/testautomation/Documents/Automation/TFS/Mem_Mobile
mvn clean

crontab -l 的输出

0 14 * * * /Users/testautomation/Documents/Automation/Schedule/Execute.sh

错误

From testautomation@Tests-iMac.xxx.local  Wed Jun 12 14:44:01 2019
Return-Path: <testautomation@Tests-iMac.xxx.local>
X-Original-To: testautomation
Delivered-To: testautomation@Tests-iMac.xxx.local
Received: by Tests-iMac.xxx.local (Postfix, from userid 501)
id 0BE233001CB411; Wed, 12 Jun 2019 14:44:00 +1000 (AEST)
From: testautomation@Tests-iMac.xxx.local (Cron Daemon)
To: testautomation@Tests-iMac.xxx.local
Subject: Cron <testautomation@Tests-iMac> /Users/testautomation/Documents/Automation/Schedule/Execute.sh
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=testautomation>
X-Cron-Env: <USER=testautomation>
X-Cron-Env: <HOME=/Users/testautomation>
Message-Id: <20190612044401.0BE233001CB411@Tests-iMac.xxx.local>
Date: Wed, 12 Jun 2019 14:44:00 +1000 (AEST)

/Users/testautomation/Documents/Automation/Schedule/Execute.sh: line 3: mvn: command not found

我已经使用自制软件安装了 maven。

mvn -version 输出:

Tests-iMac:~ testautomation$ mvn -version
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T06:00:29+11:00)
Maven home: /usr/local/Cellar/maven/3.6.1/libexec
Java version: 1.8.0_212, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home/jre
Default locale: en_AU, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.5", arch: "x86_64", family: "Mac"

最佳答案

执行脚本时使用mvn的完整路径。

#!/bin/bash 
cd /Users/testautomation/Documents/Automation/TFS/Mem_Mobile
/usr/local/Cellar/maven/3.6.1/bin/mvn clean

或者下面的脚本也应该可以工作

#!/bin/bash 
cd /Users/testautomation/Documents/Automation/TFS/Mem_Mobile
/usr/local/bin/mvn clean

关于bash - mvn clean 在终端中运行良好,但在 cron 和 bash 文件中运行不正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56555010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com