LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-10-2019, 04:46 AM   #1
Ezzmazz
LQ Newbie
 
Registered: Apr 2019
Posts: 12

Rep: Reputation: Disabled
Permission denied with my CGI in bash


Hello !

I need to create a CGI in bash in which it would be possible to generate a graph from a gnuplot script.

For the moment, I use two pages : In the first page we can find a " Generate button " :

Code:
#!/bin/bash

echo "Content-type: text/html"
echo ""

echo '
<html>
<head>
<meta http-equiv="Content-Type" content="test/html"; charset=UTF-8">
<title> CLUSTER GRAPH </title>
<h1> Cluster Graph </h1>
<hr size="4" color="blue">
</head>

<body>

<p> Press the button to generate the graph ! </p>
<form action="GNUGRAPH.sh" target="_blank">
<button name="buton">Generate</button>
</form>




</body>
</head>
</html> '
If I click on it, a new tab appears with my second page :

Code:
#!/bin/bash

echo "Content-type: text/html"
echo ""

echo "
<html>
<head>
        <title> Cluster Graph </title>
        <h1> Cluster Graph </h1>
<hr size="4" color="blue" >

</head>
<body>

<PRE>"

gnuplot gnuplot_test.txt
echo "
</PRE>

</body>
</html>
"
That should be execute my gnuplot script :

Code:
f(w) = (strlen(w) > 10 ? word(w, 1) . "\n" . word(w, 2) : w)

set title "CLUSTER 1"
set terminal png truecolor size 960, 720
set output 'cluster2.png'
set bmargin at screen 0.1
set key top center
set grid
set style data histograms
set style fill solid 1.00 border -1
set boxwidth 0.7 relative
set yrange [0:]
set format y "%g%%"
set datafile separator ","
plot "/var/www/cgi-bin/CLUSTER_1.txt" using 2:xtic(f(stringcolumn(1))) title " CPU consumption (%) ", \
'' using 3 title " RAM consumption (%)", \
'' using 0:($2+1):(sprintf("%g%%",$2)) with labels notitle, \
'' using 0:($3+1):(sprintf("     %g%%",$3)) with labels notitle
This graph should be generated when I click on the button :

https://image.noelshack.com/fichiers...3-cluster1.png

At the end, I would like the graph appaears on my page, but for the moment, I would like to see it generated in my directory /cgi-bin/.

The problem is : my graph is not generated and I don't know why. Can you explain to me my errors_log ? :

Code:
[Wed Apr 10 11:42:30.128119 2019] [cgi:error] [pid 11948] [client ::1:51078] AH01215:  , referer: http://localhost/cgi-bin/Index.sh
[Wed Apr 10 11:42:30.128322 2019] [cgi:error] [pid 11948] [client ::1:51078] AH01215:  , referer: http://localhost/cgi-bin/Index.sh
[Wed Apr 10 11:42:30.128459 2019] [cgi:error] [pid 11948] [client ::1:51078] AH01215:  , referer: http://localhost/cgi-bin/Index.sh
[Wed Apr 10 11:42:30.128613 2019] [cgi:error] [pid 11948] [client ::1:51078] AH01215:  , referer: http://localhost/cgi-bin/Index.sh
[Wed Apr 10 11:42:30.129236 2019] [cgi:error] [pid 11948] [client ::1:51078] AH01215: ^, referer: http://localhost/cgi-bin/Index.sh
[Wed Apr 10 11:42:30.130240 2019] [cgi:error] [pid 11948] [client ::1:51078] AH01215: cannot open file; output not changed, referer: http://localhost/cgi-bin/Index.sh
[Wed Apr 10 11:42:30.130832 2019] [cgi:error] [pid 11948] [client ::1:51078] AH01215: , referer: http://localhost/cgi-bin/Index.sh
[Wed Apr 10 11:42:30.131326 2019] [cgi:error] [pid 11948] [client ::1:51078] AH01215: "gnuplot_test.txt", line 5: , referer: http://localhost/cgi-bin/Index.sh
[Wed Apr 10 11:42:30.131901 2019] [cgi:error] [pid 11948] [client ::1:51078] AH01215: util.c: Permission denied, referer: http://localhost/cgi-bin/Index.sh
[Wed Apr 10 11:42:30.132313 2019] [cgi:error] [pid 11948] [client ::1:51078] AH01215: , referer: http://localhost/cgi-bin/Index.sh
Can you tell me how to achieve this ?


Thanks !
 
Old 04-10-2019, 10:45 AM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
A guess:
The apache user doesn't have write permissions in the directory, so it can't open the output file.

That would be typical. Create a new directory, owned by the apache user, then direct the output to that new directory. You can then display it from there once it's generated.
You really don't want to clutter up your cgi directory with the output of your script, anyway.
 
Old 04-11-2019, 03:24 AM   #3
Ezzmazz
LQ Newbie
 
Registered: Apr 2019
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
A guess:
The apache user doesn't have write permissions in the directory, so it can't open the output file.

That would be typical. Create a new directory, owned by the apache user, then direct the output to that new directory. You can then display it from there once it's generated.
You really don't want to clutter up your cgi directory with the output of your script, anyway.
Hello,

Thank you for your answer !

When you say " Create a new directory, owned by the apache user ", you mean : create a directory in my cgi-bin and make " chown apache:apache my_new_directory " ? If is that, it doesn't work :

I change the path of the output in my gnuplot script to " set output /var/www/cgi-bin/cluster1.png " to "set output /var/www/cgi-bin/my_new_directory " and this is my error_lor :

Code:
[Thu Apr 11 10:05:18.689298 2019] [cgi:error] [pid 15507] [client ::1:54064] AH01215:  , referer: http://localhost/cgi-bin/Index.sh
[Thu Apr 11 10:05:18.689342 2019] [cgi:error] [pid 15507] [client ::1:54064] AH01215:  , referer: http://localhost/cgi-bin/Index.sh
[Thu Apr 11 10:05:18.689388 2019] [cgi:error] [pid 15507] [client ::1:54064] AH01215:  , referer: http://localhost/cgi-bin/Index.sh
[Thu Apr 11 10:05:18.689474 2019] [cgi:error] [pid 15507] [client ::1:54064] AH01215:  , referer: http://localhost/cgi-bin/Index.sh
[Thu Apr 11 10:05:18.689588 2019] [cgi:error] [pid 15507] [client ::1:54064] AH01215: ^, referer: http://localhost/cgi-bin/Index.sh
[Thu Apr 11 10:05:18.689919 2019] [cgi:error] [pid 15507] [client ::1:54064] AH01215: cannot open file; output not changed, referer: http://localhost/cgi-bin/Index.sh
[Thu Apr 11 10:05:18.690129 2019] [cgi:error] [pid 15507] [client ::1:54064] AH01215: , referer: http://localhost/cgi-bin/Index.sh
[Thu Apr 11 10:05:18.690301 2019] [cgi:error] [pid 15507] [client ::1:54064] AH01215: "gnuplot_test.txt", line 5: , referer: http://localhost/cgi-bin/Index.sh
[Thu Apr 11 10:05:18.690664 2019] [cgi:error] [pid 15507] [client ::1:54064] AH01215: util.c: No such file or directory, referer: http://localhost/cgi-bin/Index.sh
[Thu Apr 11 10:05:18.690978 2019] [cgi:error] [pid 15507] [client ::1:54064] AH01215: , referer: http://localhost/cgi-bin/Index.sh

But I think I missed somethings and for the moment, my technical level is still weak, which doesn't help matters ! I'm a beginner in apprenticeship, so I continue to study !

Can you tell me why it doesn't work ?

Thanks !
 
Old 04-11-2019, 11:45 AM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Looks like the same error, yes?
I’m still guessing here...is the user running apache called apache?
Code:
ps aux | grep httpd
to see what it is. sometimes it defaults to www-data

Also, the output file name should be as you posted it last, including the file name...there’s no path in the script you posted.

BUT. Displaying the gnuplot command on the second page won't execute it. The script run by the form on the first page (GNUGRAPH.sh) needs to run gnuplot, then display the png in the second page.

Last edited by scasey; 04-11-2019 at 11:56 AM.
 
Old 04-12-2019, 02:24 AM   #5
Ezzmazz
LQ Newbie
 
Registered: Apr 2019
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
Looks like the same error, yes?
I’m still guessing here...is the user running apache called apache?
Code:
ps aux | grep httpd
to see what it is. sometimes it defaults to www-data

Also, the output file name should be as you posted it last, including the file name...there’s no path in the script you posted.

BUT. Displaying the gnuplot command on the second page won't execute it. The script run by the form on the first page (GNUGRAPH.sh) needs to run gnuplot, then display the png in the second page.
Hello !

Here the result of the command :

Code:
root     15575  0.2  0.0 224052  5008 ?        Ss   09:18   0:00 /usr/sbin/httpd -DFOREGROUND
apache   15576  0.0  0.0 226272  3960 ?        S    09:18   0:00 /usr/sbin/httpd -DFOREGROUND
apache   15577  0.0  0.0 226136  3112 ?        S    09:18   0:00 /usr/sbin/httpd -DFOREGROUND
apache   15578  0.0  0.0 226136  3112 ?        S    09:18   0:00 /usr/sbin/httpd -DFOREGROUND
apache   15579  0.0  0.0 226272  3820 ?        S    09:18   0:00 /usr/sbin/httpd -DFOREGROUND
apache   15580  0.0  0.0 226136  3112 ?        S    09:18   0:00 /usr/sbin/httpd -DFOREGROUND
apache   15625  0.0  0.0 226136  3112 ?        S    09:18   0:00 /usr/sbin/httpd -DFOREGROUND
root     15828  0.0  0.0 112712   976 pts/0    S+   09:18   0:00 grep --color=auto httpd

However, I found a solution to my problem...

When I run this command under RedHat 7.6 :

Code:
setenforce 0
My CGI works well and my graph appears...


I don't know why but in the long run, not sure this is very safe...
 
Old 04-12-2019, 12:58 PM   #6
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by Ezzmazz View Post
However, I found a solution to my problem...

When I run this command under RedHat 7.6 :

Code:
setenforce 0
My CGI works well and my graph appears...


I don't know why but in the long run, not sure this is very safe...
That sets SELinux to permissive mode. SELinux is not a strength of mine, sorry.
I'd start with man selinux
 
  


Reply



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
[SOLVED] how to resolve error -bash: /etc/profile: Permission denied -bash-4.2$ in password less authentication in Linux gjoshi Linux - Newbie 4 03-25-2019 12:57 PM
cgi-bin error (Permission Denied) Help! Amorgos Programming 8 09-08-2008 10:20 PM
CGI: permission denied cramer Linux - General 3 11-25-2007 07:27 PM
Permission denied executing cgi-script Geminias Linux - Networking 4 07-31-2006 10:02 PM
Python CGI script can't write files, permission denied The_Nerd Programming 4 03-17-2005 12:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:23 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
Open Source Consulting | Domain Registration