Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing unix commands from a script. 1

Status
Not open for further replies.

sucram

Programmer
May 23, 2001
75
GB
Is there a reason unix commands won't work from a script when you are using CGI to take in parameters from a webpage. I am trying to move files between directories. I have tried
`mv source destination`;
and
rename(source destination);

Neither worked, it was as if they were skipped over.
 
Give more details - like
- what platform are you working on
- operating system
- webserver
- perl "bang" line at the top - what switches are you using
- *how* are you trying to "move" and "rename" -using backticks and the shell command

A snippet of code would be helpful.
Hardy Merrill
Mission Critical Linux, Inc.
 
This is the basic idea of the code. I am working on Unix, but there will be files uploaded from NT aswell. This will be runing on a Unix web server. Without the 2 commented out lines (lines 3,4) the code works fine but I need the variable $name. When the two lines are not commented out all commands in backtick are not carried out. I am trying to move the files using the mv command in line 7. The rename function should do the same thing but it doesn't do anything either. If "or die("");" is placed after the rename function the program dies so there must be a reason why the files cannot be manipulated when lines 3,4 are included.
The files are uploaded fine and they are placed in a directory but after that I am unable to do anything that would affect the files. Nothing in backticks will work with lines 3,4 included.
The name variable is stored in a form on the web page and is passed in using CGI.
I suppose what I am looking for is a way to be able to use the backticks or a way to pass in the name parameter without using CGI or anything else that would stop the backticks working.

Switches?

#!/agl/tools/perl/bin/perl
use CGI;
#$query = new CGI;
#$name = $query->param('name');
require "./cgi-lib.pl";
$ret = &ReadParse;
`mv /users/share_users/pdf/OUT/$fname $path/ps/`;
rename("/users/share_users/pdf/OUT/$fname", "$path/ps/");

 
You may have a conflict between the CGI library and cgi-lib.pl. I think they are used for the same purpose, but in slightly different ways.

Also, your mv and rename use $fname and $path, but you are fetching a parameter called $name.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Thanks for the help. I was told of the existence of a server log and this showed me that when I was using the CGI libray the variable containing the file name was not being recognised in the path containing the source of the file..
For example the mv command was being interpreted as:

`mv /users/share_users/pdf/OUT/ $path/ps/`;

$fname was not recognised. But if it was placed after $path/ps/ it was recognised.

so it obviously couldn't work. The problem seemed to be the dot in the file name (file.ps). When I placed a backslash infront of the dot all was solved. The backslash was not required if I was not using the CGI library.

Thanks again,
Marcus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top