-1

I have created a shell file to extract an archive from .7z. The shell works fine in the terminal but in the cronjob I get an error.

The command is:

7z x /path/to/file.7z -aoa

The error I receive is:

/path/to/script.sh: line 2: 7z: command not found

I am using the full path to the .7z file and I checked my permissions so I am breaking my head to find out what I am doing wrong.

I changed my script to

#!/bin/bash
/usr/local/bin/7z x /path/to/file.7z -aoa

I now get

/bin/sh: /path/to/script.sh: Permission denied

I have checked the script, file and 7z files and all permissions are set to read/write

OK.. So I fixed the permission issue by using chmod +x on the script.

0

2 Answers 2

0

The problem is not the path to the .7z file, it's the path to the executable 7z

I'm guessing that 7z came from something like HomeBrew, so is not on the default path and your user has a .profile or similar entry that adds directories to the PATH env var.

Use which 7z command to find the full path to 7z and edit the script to use that path.

4
  • Yes, this is HomeBrew. I found the location of the command at /usr/local/bin but I am not sure what I need to do... Sep 15, 2020 at 20:03
  • Edit the script to include the full path to the command e.g. /usr/local/bin/7z x /path/to/file.7z
    – hardillb
    Sep 15, 2020 at 20:06
  • The command you recommended works fine on terminal but in the cron I get the same error "7z: command not found" Sep 15, 2020 at 20:13
  • Edit the question to show your FULL script including the modifications and the full new error.
    – hardillb
    Sep 15, 2020 at 20:27
0

Put the full path on the 7z command. The problem you're having is that cronjob doesn't have the same PATH as your shell. You can find the full path of the 7z with command -v 7z command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .