Question : Bash script does not work as a cron job

Greetings,

I have a script that runs and converts some images using ImageMagic's convert utility. If you run it in the directory it does what it's supposed to, but when you execute the script as a cron job, it can't find the directories.

I am sure it has something to do with the very first line, but even if I hard code the directory on that line prior to the *.jpg, it comes back and says it can't find the file in the directory.

So again, when I load the sript below in the directory, it runs fine, when I run it with cron, I get this error message:

ls: cannot access *.jpg: No such file or directory
Code Snippet:
1:
2:
3:
4:
5:
for img in `ls *.jpg`
do
convert -size 140x100 -resize 140x100 +profile '*' -shave 0x04 $img /home/realtordata/images/imagedownload/testthumbs/$img
 
done
Open in New Window Select All

Answer : Bash script does not work as a cron job

For cron you should use absolute paths for all file locations and commands.
1:
2:
3:
4:
5:
6:
7:
8:
9:
#!/bin/bash
 
cd /full/path/to/dir
 
for img in *.jpg
do
    /full/path/to/convert -size 140x100 -resize 140x100 +profile '*' -shave 0x04 $img /home/realtordata/images/imagedownload/testthumbs/$img
 
done
Open in New Window Select All
Random Solutions  
 
programming4us programming4us