Solved

Bash script does not work as a cron job

Posted on 2009-05-12
3
416 Views
Last Modified: 2013-12-26
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
Comment
Question by:ctoolz
3 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
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
 
LVL 58

Accepted Solution

by:
amit_g earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:ctoolz
Comment Utility
Thanks for you quick and correct response! Worked like a charm!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now