LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-24-2017, 11:10 PM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Sagle, ID
Distribution: Ubuntu 14.04
Posts: 225

Rep: Reputation: 8
Run bash script with HTML5 button - won't work


Hi I've created an index button that calls a php script that in turn calls a bash script. The bash script won't work'.

HTML5:

Code:
					<input type="button" class="hov" id="btn2g" value="Dump-Databases"	 
				onclick="window.location.href='mydbdump.php'"></input><br />
PHP:

Code:
<?php

set_include_path( 'include' );
error_reporting (E_ALL ^ E_NOTICE);

echo getcwd();

shell_exec("mydb-mysqldump.sh");
//header('Location:localhost/mydb.com/page?success=true');

?>
OUTPUT:

/home/rick/DB-Web
 
Old 09-25-2017, 01:43 AM   #2
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 2,689
Blog Entries: 3

Rep: Reputation: 1167Reputation: 1167Reputation: 1167Reputation: 1167Reputation: 1167Reputation: 1167Reputation: 1167Reputation: 1167Reputation: 1167
Your script might be fine. The problem looks to be with the HTML. The button element needs to be part of a form element. The form element should then have an 'action' attribute containing the URL pointing to your PHP script. That URL can be a relative path of course.

Can you show more of the HTML document? In particular, please show the whole form element and its attributes.
 
1 members found this post helpful.
Old 09-25-2017, 03:31 AM   #3
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,551

Rep: Reputation: 139Reputation: 139
Does a click on the button open the new URL?
If so I see 2 possible reasons for the failure:
1. if the shell script does not reside in the same directory as the calling php script you have call it with its entire path. Maybe it would be OK if you set the entire include path but I am not sure about that.set_include_path('include) will not help much I think.
2. the shell script is not executable for the web user?

Last edited by j-ray; 09-25-2017 at 03:33 AM.
 
Old 09-25-2017, 12:23 PM   #4
pizzipie
Member
 
Registered: Jun 2005
Location: Sagle, ID
Distribution: Ubuntu 14.04
Posts: 225

Original Poster
Rep: Reputation: 8
Thank you Turbocapitalist and j-ray,

Thanks for your hints I figured out what was wrong and it now works ok.

R

Last edited by pizzipie; 09-25-2017 at 01:28 PM.
 
Old 09-26-2017, 11:47 AM   #5
dedec0
Member
 
Registered: May 2007
Posts: 642

Rep: Reputation: 27
I want to suggest to you, pizzipie, that tell us what was wrong and what is your whole working situation now. Making a button execute a shell script is something I may want to do eventually, and I decided to read this thread to get a bit more informed about the subject and its possible problems. But, with everything said in this thread until now, I am basically in the same point I was before starting it.
 
Old 09-26-2017, 12:14 PM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 6,971
Blog Entries: 4

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
Originally Posted by pizzipie View Post
I figured out what was wrong and it now works ok.
please share your solution; life's a 2-way street.
others will benefit.
 
Old 09-26-2017, 12:46 PM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,448

Rep: Reputation: 420Reputation: 420Reputation: 420Reputation: 420Reputation: 420
Make sure you set a strategy for button debouncing.
I mean not to execute more than one database dump when multi clicking the button by accident or not.
 
Old 09-26-2017, 02:41 PM   #8
pizzipie
Member
 
Registered: Jun 2005
Location: Sagle, ID
Distribution: Ubuntu 14.04
Posts: 225

Original Poster
Rep: Reputation: 8
Thanks all,

I have marked this thread as UNSOLVED because of your input and in addition I have further problems which I hope you can help me with..

Re: Buttons I have 18 <input> statements in the form which contain the type="button" which all work fine.
Example: <input type="button" class="hov" id="btn2g" value="Dump-Databases"

I did have problems with which directory I was in which prevented the script to work:

Code:
| cat tmp_sqlhead.sql - tmp_sqlend.sql  | gzip -fc > "/home/rick/DB-Web/mydb-bakup-folder/"$d"$I.sql.gz"
I changed gzip -fc > DB-Web/mydb-bakup-folder to what you see above in the code.

This allowed the script to run.

However, this created another problem.

When the script runs the files are created and stored in the proper folder 'mydb-bakup-folder' BUT there is no output other than /home/rick/DB-Web which is the PWD. I want to see what files are being processed. I guess this is the old bug-a-boo of server-client processing.

To solve this I created a launcher which calls my bash script and does show me the output BUT only in a tiny new window which is very hard to see. Is there any way to show the output in a normal display window? Or at least format the 'tiny new window' See my latest thread.
 
Old 09-27-2017, 03:11 PM   #9
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,515
Blog Entries: 6

Rep: Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426
Quote:
Originally Posted by pizzipie View Post
Hi I've created an index button that calls a php script that in turn calls a bash script. The bash script won't work'.
"Won't work" is not a useful problem description. When describing problems please tell us at least what you are expecting it to do, and how that differs from what it is actually doing.

The first thing I see is that your button only sets the window.location.href attribute (i.e. loads the new page), it does not submit any other form elements and in particular is not equivalent to an HTTP POST request which puts variable values into the PHP environment.

Having then loaded the page (presumably the PHP script posted) from the new location, it is working exactly as indicated, printing the working directory (and discarding the output of the shell_exec(...) operation, whatever it may be).

Quote:
Originally Posted by pizzipie View Post
Re: Buttons I have 18 <input> statements in the form which contain the type="button" which all work fine.
Example: <input type="button" class="hov" id="btn2g" value="Dump-Databases"
It would be helpful if you would show us the complete <input...> tag, otherwise we cannot know whether it still includes the onclick handler which loads a different page, or whether it submits the parent form.

Quote:
Originally Posted by pizzipie View Post
This allowed the script to run.

However, this created another problem.

When the script runs the files are created and stored in the proper folder 'mydb-bakup-folder' BUT there is no output other than /home/rick/DB-Web which is the PWD. I want to see what files are being processed. I guess this is the old bug-a-boo of server-client processing.
Client-server processing is not a bug-a-boo, it is the way things work. As we have noted in previous threads, it is important to understand how that works in order to understand what is happening when things don't work.

But "this allowed the script to run" tells us nothing useful - it was running before as far as we can tell. Please be complete in your descriptions of what the script is expected to do, and what it is actually doing - how do you know it is running, and how can those here know what is happening?

Please remember that we cannot see the whole picture of what is happening,, only what you tell us.

If this is the script posted above, then it is doing exactly what you told it to do:

Code:
echo getcwd();

shell_exec("mydb-mysqldump.sh");
Which is, echo the working directory and discard the output of the shell_exec(...) function, whatever it may be.

What were you expecting it to do?


Quote:
Originally Posted by pizzipie View Post
To solve this I created a launcher which calls my bash script and does show me the output BUT only in a tiny new window which is very hard to see. Is there any way to show the output in a normal display window? Or at least format the 'tiny new window' See my latest thread.
Please do not ask members to go in search of other threads - if you refer to them please link to them.

Also, please do not open new threads if this is essentially the same problem, which appears likely.

First it was an HTML5 button problem, now in the new thread it is a terminal window size problem, but you still have not told us what it is you are actually trying to accomplish, or anything about the actual script running in the shell_exec(...) function mentioned here, or its execution context, which I suspect is the real problem.

This is beginning to look like another X-Y Problem.

To get help, please describe for us what you are actually trying to accomplish, and in what context (web server, desktop application, terminal, bash script, PHP code, etc.). Demystify it for us, please.

Last edited by astrogeek; 09-29-2017 at 01:40 AM. Reason: typo
 
1 members found this post helpful.
Old 09-29-2017, 12:16 PM   #10
pizzipie
Member
 
Registered: Jun 2005
Location: Sagle, ID
Distribution: Ubuntu 14.04
Posts: 225

Original Poster
Rep: Reputation: 8
A picture is worth a thousand words eh?

Apparently I can't explain myself properly.
Attached Thumbnails
Click image for larger version

Name:	Displays.png
Views:	11
Size:	207.7 KB
ID:	25995  
 
Old 09-29-2017, 12:34 PM   #11
dedec0
Member
 
Registered: May 2007
Posts: 642

Rep: Reputation: 27
In #10 picture, how did you make the little black window on the right appear? Did you:

1. Did you doubleclick its icon in the desktop?

2. Did you doubleclick its icon in a file manager window?

3. Did you type its full path in the terminal window in the left?

4. Did you type part of its path preceeding it with "./" in the terminal window in the left?

If you did 3 or 4, the script output would be shown the in left window, except if the little window is somehow invoked by that command, but this will be a different problem.

Last edited by dedec0; 09-29-2017 at 12:45 PM.
 
Old 09-29-2017, 01:05 PM   #12
pizzipie
Member
 
Registered: Jun 2005
Location: Sagle, ID
Distribution: Ubuntu 14.04
Posts: 225

Original Poster
Rep: Reputation: 8
Sorry I broke 'protocal'


Code:
echo getcwd();

shell_exec("mydb-mysqldump.sh");
Quote:
Which is, echo the working directory and discard the output of the shell_exec(...) function, whatever it may be.

What were you expecting it to do?
The attachment shows the output from invoking mydb-mysqldump.sh on the command line. This is what I expect.

When I invoke it with the launcher I get that little black background screen.

The third thing I tried was to invoke it thru php. This led to your statement above. I don't understand why you say the code tells it to discard the output. However, the script works in that all the files are 'Dumped'.
Attached Thumbnails
Click image for larger version

Name:	mysqldump-output.png
Views:	2
Size:	91.6 KB
ID:	25996  
 
Old 09-29-2017, 02:39 PM   #13
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,515
Blog Entries: 6

Rep: Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426Reputation: 2426
Quote:
Originally Posted by pizzipie View Post
Sorry I broke 'protocal'
It isn't about breaking any strict protocol. It is all about providing a complete and useful problem description so that ohters can understand the problem and offer helpful advice without heading down blind alleys.

Quote:
Originally Posted by pizzipie View Post
The attachment shows the output from invoking mydb-mysqldump.sh on the command line. This is what I expect.
Then you should have said this in post #1, not post #12, so that we would know what you were expecting and how the actual result differed from the expected result.

And the answer was indeed guessed here:

Quote:
If this is the script posted above, then it is doing exactly what you told it to do:
Code:
echo getcwd();

shell_exec("mydb-mysqldump.sh");
Which is, echo the working directory and discard the output of the shell_exec(...) function, whatever it may be.
Your code tells it to discard the output of whatever runs in the shell_exec(...) function.

Quote:
Originally Posted by pizzipie View Post
The third thing I tried was to invoke it thru php. This led to your statement above. I don't understand why you say the code tells it to discard the output. However, the script works in that all the files are 'Dumped'.
Then please consider why I may have said that and see the PHP manual page for shell_exec(...) to understand how to display the output instead of discarding it.

Remember, the better and more precise the question, the better and more useful the answers.

As this was the third thing you tried I suspect we may still be working on part Z or an X-Y-Z problem. If this does not provide the answer you ultimately need then please pause and reconsider what your original goal was, and what did not work. Then try to explain just that in simplest, complete terms. This will help others more quickly understand the problem and provide you with the best answers.

And remember that ultimately, programming is not about trying things until something happens to work. Programming is all about fully understanding the task at hand and crafting a solution which best meets the clear requirements of that task. When things do not work it may be because the code is incorrectly implemented, or it may be because the requirements were not correctly understood. Knowing which is key to success!

Last edited by astrogeek; 09-29-2017 at 02:41 PM. Reason: typos
 
1 members found this post helpful.
Old 09-29-2017, 03:40 PM   #14
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 6,971
Blog Entries: 4

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
^ strange, i just saw that same screenshot in another thread...
here: https://www.linuxquestions.org/quest...3/#post5764437
i wonder what one has to do with the other...
 
Old 09-29-2017, 03:46 PM   #15
pizzipie
Member
 
Registered: Jun 2005
Location: Sagle, ID
Distribution: Ubuntu 14.04
Posts: 225

Original Poster
Rep: Reputation: 8
BOY, how I blew that shell_exec call I don't know. I have read the reference on it too.

My bad. The mysqldump.php works fine now.

I will concentrate on the other thread now to try and get the Screen Display problem solved.

R
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
If I push a button on one input device, have one script run, else, run the other? Automatic Linux - Software 2 04-14-2013 03:17 AM
I created a launcher for a bash(sh) script but it won't run p3aul Ubuntu 14 06-16-2012 05:06 AM
sshfs in bash script - won't run in called terminal? basd Linux - General 3 03-17-2012 06:10 PM
[SOLVED] Command line works, won't work from inside bash script w6lsn Programming 4 02-17-2011 06:45 AM
My BASH script work perfect when i run it manualy, but not when it run in the crontab roqarg Linux - Newbie 30 05-06-2010 02:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration