LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 05-14-2010, 12:20 PM   #1
SteveMack2015
LQ Newbie
 
Registered: May 2010
Posts: 1

Rep: Reputation: 0
Running Bash script in PHP script


Hey guys,

I'm having a little trouble here - I have a php script that parses a .csv file and creates a bash script (.sh) along with a few other .txt files (not relevant). I then try to run the bash script at the end of the PHP script:

exec("sh $folderName.sh");

and it does nothing. After running the php script (which creates the bash script successfully), I've also tried running the bash script in terminal - again nothing.

Although, when I copy the contents of the bash script into a new file in XCode (I'm running OS X) and save it, overwriting the old file, then I can run the bash script in terminal and it works correctly. Doesn't make much sense to me since the file is exactly the same, just overwritten outside of the php script...

Any ideas?

Thanks
 
Old 05-14-2010, 02:41 PM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 13,778

Rep: Reputation: 2349Reputation: 2349Reputation: 2349Reputation: 2349Reputation: 2349Reputation: 2349Reputation: 2349Reputation: 2349Reputation: 2349Reputation: 2349Reputation: 2349
Quote:
Originally Posted by SteveMack2015 View Post
Hey guys,

I'm having a little trouble here - I have a php script that parses a .csv file and creates a bash script (.sh) along with a few other .txt files (not relevant). I then try to run the bash script at the end of the PHP script:

exec("sh $folderName.sh");

and it does nothing. After running the php script (which creates the bash script successfully), I've also tried running the bash script in terminal - again nothing.
Several things come to mind. Have you tried putting the "#!/bin/bash" as the first line of the shell script, and calling it with just the script name? Also, are the permissions on the file ok? Maybe try to call it with "system" instead of 'exec', and see what happens. Also, for debugging purposes, you could try to output the variables to a separate text file, to see what you're getting. And you mention overwriting...are you closing the file prematurely, or maybe using a file create instead of append somewhere?
Quote:
Although, when I copy the contents of the bash script into a new file in XCode (I'm running OS X) and save it, overwriting the old file, then I can run the bash script in terminal and it works correctly. Doesn't make much sense to me since the file is exactly the same, just overwritten outside of the php script...
And now comes the obligatory "You know this is LINUXquestions, right?" statement, after you said you used OSX. But this would be a better thread in the "Programming" forum.
 
Old 05-14-2010, 03:34 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Quote:
Originally Posted by SteveMack2015 View Post
exec("sh $folderName.sh");
  1. What's the dollar sign for?
  2. This isn't MacQuestions. Do you even have Linux?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a bash script in PHP Nerdstock2005 Programming 14 12-09-2008 03:28 PM
Is 'nice' inherited to child processes? e.g. bash script/php script that calls MySQL SirTristan Linux - Newbie 1 12-04-2008 12:57 AM
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 09:10 PM
LXer: Title: PHP/MySQL Classifieds Script AddAsset1.php Script Insertion LXer Syndicated Linux News 0 07-02-2006 06:21 PM
running su from a bash script caminoix Programming 7 12-28-2005 03:41 PM


All times are GMT -5. The time now is 10:49 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration