• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Create & Delete file by CGI Perl Script?

 
Ranch Hand
Posts: 630
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to create text file in specific folder, write in it something , read it for checking, then delete it.
But at very first step I got error.

1. Creating file problem:-

Here is cgi perl script:-

Got error


print() on closed filehandle $fh at /usr/lib/cgi-bin/login.cgi line 22 (#1)
(W closed) The filehandle you're printing on got itself closed sometime
before now. Check your control flow.

[Sat Dec 12 11:33:12 2015] [debug] mod_deflate.c(700): [client xxx.xxx.xxx.xxx] Zlib: Compressed 116 to 85 : URL /cgi-bin/login.cgi, referer: http://xxx.xxxx.xxx.xxx/



2. Deleting existing file:-
I used 4 different ways for already existed file.(I create text file & give it to 777 permission so I can see after command 'ls -al' in terminal is as '-rwxrwxrwx' for hello.txt ).
2.1 by 'unlink'


Then I got following output:-

file Removed successfully by unlink '/home/hello.txt' Permission denied



& Error as follows:-

[Sat Dec 12 11:45:25 2015] [debug] mod_deflate.c(700): [client xxx.xxx.xxx.xxx] Zlib: Compressed 138 to 112 : URL /cgi-bin/login.cgi, referer: http://xxx.xxx.xxx.xxx/



2.2 By `$command`


Then I got following error:-

Can't exec "del": No such file or directory at /usr/lib/cgi-bin/login.cgi line
13 (#1)
(W exec) A system(), exec(), or piped open call could not execute the
named program for the indicated reason. Typical reasons include: the
permissions were wrong on the file, the file wasn't found in
$ENV{PATH}, the executable in question was compiled for another
architecture, or the #! line in a script points to an interpreter that
can't be run for similar reasons. (Or maybe your system doesn't support
#! at all.)

[Sat Dec 12 12:50:36 2015] [debug] mod_deflate.c(700): [client xxx.xxx.xxx.xxx] Zlib: Compressed 159 to 122 : URL /cgi-bin/login.cgi, referer: http://xxx.xxx.xxx.xxx/



2.3 by exec


Then I got following error:-

Statement unlikely to be reached at /usr/lib/cgi-bin/login.cgi line 13 (#1)
(W exec) You did an exec() with some statement after it other than a
die(). This is almost always an error, because exec() never returns
unless there was a failure. You probably wanted to use system()
instead, which does return. To suppress this warning, put the exec() in
a block by itself.

(Maybe you meant system() when you said exec()?)
Can't exec "del": No such file or directory at /usr/lib/cgi-bin/login.cgi line
12 (#2)
(W exec) A system(), exec(), or piped open call could not execute the
named program for the indicated reason. Typical reasons include: the
permissions were wrong on the file, the file wasn't found in
$ENV{PATH}, the executable in question was compiled for another
architecture, or the #! line in a script points to an interpreter that
can't be run for similar reasons. (Or maybe your system doesn't support
#! at all.)

[Sat Dec 12 12:52:40 2015] [debug] mod_deflate.c(700): [client xxx.xxx.xxx.xxx] Zlib: Compressed 159 to 121 : URL /cgi-bin/login.cgi, referer: http://xxx.xxx.xxx.xxx/



2.4 by system command


Then I got following error:-

Can't exec "cd": No such file or directory at /usr/lib/cgi-bin/login.cgi line
12 (#1)
(W exec) A system(), exec(), or piped open call could not execute the
named program for the indicated reason. Typical reasons include: the
permissions were wrong on the file, the file wasn't found in
$ENV{PATH}, the executable in question was compiled for another
architecture, or the #! line in a script points to an interpreter that
can't be run for similar reasons. (Or maybe your system doesn't support
#! at all.)

Can't exec "m": No such file or directory at /usr/lib/cgi-bin/login.cgi line 13 (#1)
(W exec) A system(), exec(), or piped open call could not execute the
named program for the indicated reason. Typical reasons include: the
permissions were wrong on the file, the file wasn't found in
$ENV{PATH}, the executable in question was compiled for another
architecture, or the #! line in a script points to an interpreter that
can't be run for similar reasons. (Or maybe your system doesn't support
#! at all.)

[Sat Dec 12 12:55:27 2015] [debug] mod_deflate.c(700): [client xxx.xxx.xxx.xxx] Zlib: Compressed 158 to 120 : URL /cgi-bin/login.cgi, referer: http://xxx.xxx.xxx.xxx/



I am so much confuse how to create text file & Delete it!
Need Expert guidance!
 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think the file is ever getting opened. Try:

This won't correct the problem but it will help diagnose it. I think CGI programs have limited or no ability to write to the client's disk server.

The trick is, the script runs as a "user" that usually doesn't have many permissions. Are you in control of the web server? Can the user that is running the CGI script write to the server?
reply
    Bookmark Topic Watch Topic
  • New Topic