0

I'm running a web server on a Pi3B+, using Apache. This is for an in-house library project, and the machine runs on its own AdHoc network. It will never have network contact with the outside world, so I'm not worried about security. Through a cgi script, I need to trigger a cp command, but that command is getting ignored. Here's a very simple bash script that isn't working:

echo "Content-type: text/html"
echo ""
echo '<html>'
echo '<head><title>Blah blah blah</title></head>'
echo 'Script is running'
echo '<body>'
/bin/cp /home/pi/query.sh /home/pi/newfile.sh
echo '</body></html>’

Similarly, I can't mount an attached drive, echo text to a file, or do anything else that manipulates files or volumes. I understand opening things up this way is a big security hole, but again, security is not an issue in this case. What can I do to allow this kind of access?

EDIT: The script is executing – it's properly echoing text back to the client browser.

Thanks!

  • Not enough information. Have you enabled CGI scripts? Have you enabled the language for CGI (bash is an unusual choice)? Have you marked the script executable? – joan Jul 19 '19 at 15:27
  • Oops. Left that part out. Original code snippet is now edited to show that CGI scripts are enabled. – Ben Long Jul 19 '19 at 17:12
  • Programming CGI scripts really does not belong to Raspberry Pi! Please ask at stackoverflow.com – Ingo Jul 19 '19 at 17:22
0

I copied and executed your code on a Pi3B+ and got an error. The last single-quote on

echo'<body></html>'

is the wrong type (looks like a start-single-qoute). This could just be a copy and paste error and not the issue. However, once I fixed that, the cp command worked as expected.

|improve this answer|||||
  • This does not answer a question to Raspberry Pi. – Ingo Jul 19 '19 at 20:38
  • Thanks, tbitson. Alas, it was just a copy/paste problem. The single-quote is fine on mine. As near as I can tell, this is a permissions problem, so it's interesting that it's working for you. On my machine, Apache is still owned by www-data. Have you changed your permissions for that account? – Ben Long Jul 21 '19 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.