0

I'm trying to execute a shell script to convert some images from .png to .tif using the command convert.

I have written a short shell script:

#! /bin/bash
convert -adaptive-resize 150% /Applications/MAMP/htdocs/test/1.png /Applications/MAMP/htdocs/test/1.tif
convert -adaptive-resize 150% /Applications/MAMP/htdocs/test/2.png /Applications/MAMP/htdocs/test/2.tif
convert -adaptive-resize 150% /Applications/MAMP/htdocs/test/3.png /Applications/MAMP/htdocs/test/3.tif
convert -adaptive-resize 150% /Applications/MAMP/htdocs/test/4.png /Applications/MAMP/htdocs/test/4.tif
convert -adaptive-resize 150% /Applications/MAMP/htdocs/test/5.png /Applications/MAMP/htdocs/test/5.tif
convert -adaptive-resize 150% /Applications/MAMP/htdocs/test/6.png /Applications/MAMP/htdocs/test/6.tif
convert -adaptive-resize 150% /Applications/MAMP/htdocs/test/7.png /Applications/MAMP/htdocs/test/7.tif
convert -adaptive-resize 150% /Applications/MAMP/htdocs/test/8.png /Applications/MAMP/htdocs/test/8.tif
convert -adaptive-resize 150% /Applications/MAMP/htdocs/test/9.png /Applications/MAMP/htdocs/test/9.

If I run this script from the terminal it works as expected.

Instead if I launch this from whithin a php page it doesn't.

I'm using this code:

exec("bash /Applications/MAMP/htdocs/test/convertpngtif.sh");

How can I solve this?

11
  • When you launch it from within a php page, do you get any error messages? Commented Nov 12, 2013 at 11:07
  • The user PHP runs as probably doesn't have permissions to access that script. Commented Nov 12, 2013 at 11:07
  • Try this : shell_exec("bash/Applications/MAMP/htdocs/test/convertpngtif.sh"); Commented Nov 12, 2013 at 11:09
  • @TecBrat No I don't get any error message Commented Nov 12, 2013 at 11:09
  • @vascowhite I'm sure that's the problem, how can I solve this? Commented Nov 12, 2013 at 11:11

2 Answers 2

1

This is a permissions problem. You need to allow the user that PHP runs as to have access to the sh file.

PHP usually runs as www-data, that being the case you can open a terminal and run something like:-

chown www-data:www-data /Applications/MAMP/htdocs/test/convertpngtif.sh

I don't know how your system is set up, so you may have to sudo that command.

You will have to make sure that www-data also has access to the files accessed by the bash script in a similar way, so just the following command may work:-

chown -R www-data:www-data /Applications/MAMP/htdocs/test/
Sign up to request clarification or add additional context in comments.

2 Comments

chown: www-data: Invalid argument
Ah, sorry I thought you were on Linux. Didn't spot the OSX tag, what a duffer! Can't help any further, sorry. Although it looks as if the syntax is the same ss64.com/osx/chown.html
0

Solution: use full path in the shell script.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.