I have a very simple bash script

#!/bin/bash
count=`ls | wc -l`
mkdir Folder$count

This script works when I execute it manually but fails to execute in the crontab. All the permissions on the file for execution are okay.

I have tried the following, put the output of the PATH variable in the crontab entry. Below is my my config in the crontab.

PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/workspace
* * * * * /opt/workspace/makedir

In /var/log/syslog, I could see that the cron executes the script every minute. So what am I missing?

有帮助吗?

解决方案

I guess the working directory of cron is /. add a cd /path/to/your/working/directory to your script and it'll probably work.

The default cron executing environment is very limited, but I think ls, wc and mkdir will be found

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top