Search code examples
linuxmacoscron

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 [email protected]  Fri May 22 07:40:00 2020
Return-Path: <[email protected]>
X-Original-To: myuserdev
Delivered-To: [email protected]
Received: by myusers-Mac.local (Postfix, from userid 501)
    id DF4F330036B4BD; Fri, 22 May 2020 07:40:00 -0700 (PDT)
From: [email protected] (Cron Daemon)
To: [email protected]
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: <[email protected]>
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.


Solution

  • 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