简体   繁体   中英

Why crontab: not such file or directory even if the folder exists and has 777 permission?

I am trying to run the next command "mvn clean test" scheduled by crontab, but it seems that for crontab the project folder does not exists I get the next report from crontab

From myuserdev@myusers-Mac.local  Fri May 22 07:40:00 2020
Return-Path: <myuserdev@myusers-Mac.local>
X-Original-To: myuserdev
Delivered-To: myuserdev@myusers-Mac.local
Received: by myusers-Mac.local (Postfix, from userid 501)
    id DF4F330036B4BD; Fri, 22 May 2020 07:40:00 -0700 (PDT)
From: myuserdev@myusers-Mac.local (Cron Daemon)
To: myuserdev@myusers-Mac.local
Subject: Cron <myuserdev@myusers-Mac> cd Users/myuserdev/qa-automation/01LoginProject/myuserTC && mvn clean test
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=myuserdev>
X-Cron-Env: <USER=myuserdev>
X-Cron-Env: <HOME=/Users/myuserdev>
Message-Id: <20200522144000.DF4F330036B4BD@myusers-Mac.local>
Date: Fri, 22 May 2020 07:40:00 -0700 (PDT)

/bin/sh: line 0: cd: Users/myuserdev/qa-automation/01LoginProject/myuserTC: No such file or directory

This is my crontab command

    */2 * * * * cd Users/myuserdev/qa-automation/01LoginProject/myuserTC && mvn clean test

The project folder exists and has the permission 777, I read the other answers about this problem in other posts but I couldn't fix this problem. I hope you guys can help me.

Horacio, use absolute paths.

 */2 * * * * cd /Users/myuserdev/qa-automation/01LoginProject/myuserTC && mvn clean test

I think is a better practice to use SCRIPTS in CRON.

*/2 * * * * /scripts/cleanhome.sh

cleanhome.sh

#!/bin/bash
cd /Users/myuserdev/qa-automation/01LoginProject/myuserTC && mvn clean test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM