Delete Files with CGI Bash Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete Files with CGI Bash Script
# 1  
Old 01-18-2011
Delete Files with CGI Bash Script

Hi. I could use some help with my problem. I am creating a website. One option on this website is to delete a specified file, say an image, when the user clicks on it. I want to do this with CGI. I believe bash will be the easiest since I will just type the command "rm file". I also do not know Perl. I am, however, having trouble doing any file manipulation with my cgi-script. I did chmod 777 in case that was the problem. The HTML output works fine, the command "mkdir /testcgi" is not executed. Well, the directory testcgi is not created after going to the file online. The cgi file was created with sudo, not sure if that makes a difference.

HTML Code:
#!/bin/bash
echo "Content-type: text/html"
echo ""

mkdir /test
mkdir /home/crimsonsecurity/testt

# our html code
echo "<html>"
echo "<head><title>Hello CGI</title></head>"
echo "<body>"
echo "<pre>"

# print out the environment settings
/usr/bin/env

echo "</pre>"
echo "</body>"
echo "</html>"
# 2  
Old 01-18-2011
Are you sure its not a permissions issue ?
Most web servers "chroot" to the main documents area, and therefore your paths may be incorrect, or indeed you may not have permission to alter directories or files. I would start easy and try a "touch foo" and see if the file is created in the cgi-bin or doc areas on the web server.

I would also capture the stderr to see if there is any error message:
Code:
touch foo 2>&1


Last edited by citaylor; 01-18-2011 at 02:13 PM.. Reason: extra debugging info
# 3  
Old 01-18-2011
Thanks for the quick reply. This is the error I got with touch: "touch: cannot touch `foo': Permission denied." I added "grep da * 2> grep-errors.txt" to capture the stderr 2 output. I am the server admin as this is for my school project.

-Thanks

Edit: Link to my script: http://crimsonsecurity.dyndns.org/cgi-bin/del.cgi

I set the permissions on the directory that I need to delete files in to 777 with "chmod -R 777 /folder." I was able to create a directory where I needed to. All I need to do is delete files from this script. What is the most secure way to do this? Reading man chmod, I need to set only the write bit for all users, or just for www? Is that true?

Last edited by JMooney5115; 01-18-2011 at 02:55 PM.. Reason: add link
# 4  
Old 01-18-2011
I would try running an "id" within the script to see what userid and groups the cgi is running as. Once you know that, you can either "chown" or "chgrp" the directory and just give specific user rights, or if you cant do that, you can figure out what the minimum rights are.
# 5  
Old 01-18-2011
After more time than it should have taken I have figured it out. It was a permission error which I used "chgrp" to correct.

Thanks for your help!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Calling bash script from CGI

Hi, I am having two individual scripts Script 1): CGI script - is a simple script which trigger bash script Script 2): Bash script - is a script which execute which collects file system utilization information from all the Unix servers If I am executing CGI script manually from command... (2 Replies)
Discussion started by: Naveen.6025
2 Replies

2. Programming

Bash script - find command with delete and exec

hi all, i have devised a script that starts in /restored/ and in there, there are a lot of sub folders called peoples names and in the sub folders are files/folders and it deletes the data in the sub folders BUT not the sub folder itself and it should then touch a file in all the sub folders... (3 Replies)
Discussion started by: robertkwild
3 Replies

3. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

4. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

5. Web Development

problem with exporting vairable from one perl cgi to another perl cgi script while redirecting.

Can anyone tell me how to export a variable from one perl CGI script to another perl cgi script when using a redirect. Upon running the login.pl the user is prompted to enter user name and password. Upon entering the correct credentials (admin/admin) the user is redirected to welcome page. My... (3 Replies)
Discussion started by: Arun_Linux
3 Replies

6. Homework & Coursework Questions

Run Program from Bash CGI-Script

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: This is a problem I am having with my 2 semester senior project. I have a LAMP server running Ubuntu 9.10 with... (8 Replies)
Discussion started by: JMooney5115
8 Replies

7. Shell Programming and Scripting

cgi script to print all .png files on a single page

Hi guys I'm relativley new to Perl, and have not touched html before, im trying to write a cgi script that prints all images on a single html page from a given directory. Im using perl to gather stats, rrdtool to update and create graphs now i just need to print these graphs all onto 1 index.cgi... (3 Replies)
Discussion started by: jeffersno1
3 Replies

8. Shell Programming and Scripting

Perl cgi script to call bash script?

Novice to perl here. I have created a simple web page in perl, with only one submit button. I would like to execute a bash script on the same server when this button is clicked on. Is this possible in perl? I have spent a few days researching this and am unable to find any useful information.... (0 Replies)
Discussion started by: pleonard
0 Replies

9. Shell Programming and Scripting

Wrapping a bash script for CGI

I hope its ok to start a new thread, I was going to use my existing one but thought a new one would better clarify things and provide better search for future reference. Well I have my bash program working now, all nice, user input validated, output formatted, everything is looking sexy. Now... (2 Replies)
Discussion started by: andyj
2 Replies

10. Shell Programming and Scripting

CGI passing arrays/hashes to another CGI script

If I have a Perl CGI script (script01), which fills an array(s) with information and outputs a HTML page with a link to another CGI page (script02); is there anyway to pass the array(s) from "script01" to "script02" when the page visitor clicks the link? Hope that makes sense! :) (2 Replies)
Discussion started by: WIntellect
2 Replies
Login or Register to Ask a Question