Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Bash script does not work as a cron job

Posted on 2009-05-12
3
Medium Priority
?
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 24370018
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 2000 total points
ID: 24370027
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
ID: 31580753
Thanks for you quick and correct response! Worked like a charm!
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

636 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