2

I have already tried half of askubuntu but still not succeeding. I got the following shell script:

#!/bin/bash
echo "test" > "/mnt/ssd/test.txt"
echo "test"

And the following crontab -e line:

* * * * * /mnt/ssd/test.sh > /mnt/ssd/cron.log

When I add a line to the cron.log file manually, it will be empty each new minute what tells me the cron is being fired.

I also tried the following cronjob:

* * * * * env > /mnt/ssd/env.output

This gave me these values:

LANGUAGE=nl_NL.UTF-8
HOME=/home/pi
LOGNAME=pi
PATH=/usr/bin:/bin
LANG=nl_NL.UTF-8
SHELL=/bin/sh
LC_ALL=nl_NL.UTF-8
PWD=/home/pi

It again tells me the cron is working and the SHELL is correct right?

I tried this cron as well:

* * * * * PATH=/bin:/sbin:/usr/bin:/usr/sbin /mnt/ssd/test.sh > /mnt/ssd/cron.log

Neither this writes anything to the cron.log file or is creating the test.txt file.

I am kinda confused. If my PATH is wrong am I trying to correct this in the right manner or is something else incorrect?

EDIT: thanks to @steeldrive it was found that the drive this script was located on was mounted with noexec type. Meaning a bash file can not normally be executed. Placing 'bash' in front of the command made it work. The command now looks like:

* * * * * bash /mnt/ssd/test.sh > /mnt/ssd/cron.log 2>&1

the 2>&1 is added so errors would also be outputted to the log file.

12
  • Is the script executable? can the user whose crontab you used write to /mnt/ssd? what does grep CRON /var/log/syslog show? – steeldriver Oct 25 '19 at 12:29
  • @steeldriver yes it is executable and does what it should using the terminal itself. output: (pi) CMD (PATH=/bin:/sbin:/usr/bin:/usr/sbin /mnt/ssd/test.sh > /mnt/ssd/cron.log) and also: (CRON) info (No MTA installed, discarding output) (because of mail but this should not matter right?) – Mart Oct 25 '19 at 12:33
  • if you want to append line to a file you should use >> – bac0n Oct 25 '19 at 12:35
  • 1
    Is /mnt/ssd mounted with the noexec option? check the output of mount | grep ssd – steeldriver Oct 25 '19 at 13:15
  • 2
    @Mart right - so it is mounted noexec and hence won't be directly executable - although you should still be able to use bash /mnt/ssd/test.sh. See for example Permission denied when running “./script.sh”, but works when running “bash script.sh” – steeldriver Oct 25 '19 at 13:24
0

Ok so, based on the input given by @steeldriver, we managed to obtain a solution.

The bash script is located on a mount which has been mounted by the noexec type. Meaning the bash files cannot be executed straightforward. This was found using the command:

mount | grep ssd

The solution however is simple: add bash in front of the crontab -e command:

* * * * * bash /mnt/ssd/test.sh > /mnt/ssd/cron.log 2>&1

The 2>&1 part is added in this line as well so the error logs are also placed inside the cron.log file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.