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
Question
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?
Solution
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