• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

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

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

0
ctoolz
Asked:
ctoolz
1 Solution
 
ozoCommented:
how did you hard code the directory on that line prior to the *.jpg?
what is pwd whe you run it, and what is pwd when cron runs it?
0
 
amit_gCommented:
For cron you should use absolute paths for all file locations and commands.

#!/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

0
 
ctoolzAuthor Commented:
Thanks for you quick and correct response! Worked like a charm!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now