- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- system command not working within CGI script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 06:21 AM
09-11-2006 06:21 AM
I am trying to execute the following sub routine
sub reset_config
{
my $dbh = shift;
my $sth;
system("mv /tftpboot/processed/* /tftpboot");
if ($? == -1) {
print "failed to execute: $!\n";
}
elsif ($? & 127) {
printf "child died with signal %d, %s coredump\n",
($? & 127), ($? & 128) ? 'with' : 'without';
}
else {
printf "child exited with value %d\n", $? >> 8;
}
$sth = $dbh->prepare ("delete from tblConfig");
$count = 0;
$count += $sth->execute ();
$sth->finish ();
print p ("Removed all configuration from tblConfig");
}
This is called via a CGI script. For some reason I am getting a return value of 1 for the mv command, yet the delete from tblConfig works ok. If I run the code from the shell, it works.
Any ideas ? Have checked file permissions and all appears to be ok
TIA
Steve
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 06:25 AM
- Tags:
- mv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 06:28 AM
09-11-2006 06:28 AM
Re: system command not working within CGI script
The return code changes to a 127, as opposed to a 1.
Hmmm
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 06:33 AM
09-11-2006 06:33 AM
Re: system command not working within CGI script
I would also change:
system("mv /tftpboot/processed/* /tftpboot");
to
$status = system("mv /tftpboot/processed/* /tftpboot");
so that there is a more direct connection to the actual exit status of the system function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 06:33 AM
09-11-2006 06:33 AM
Re: system command not working within CGI script
sub upload_files
{
print p ("In upload files");
system("/usr/red2/scripts/configUpload.pl");
if ($? == -1) {
print "failed to execute: $!\n";
}
elsif ($? & 127) {
printf "child died with signal %d, %s coredump\n",
($? & 127), ($? & 128) ? 'with' : 'without';
}
else {
printf "child exited with value %d\n", $? >> 8;
}
}
This returns with a 13, again, when I manually run the script all is ok.
Just going to leave the office,go home and pick this up when I get in.
It's for my masters assignment which should have been handed in today !!
grateful for all input
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 06:37 AM
09-11-2006 06:37 AM
Re: system command not working within CGI script
test-suse:/tftpboot # ls -ld processed/
drwxrwxrwx 2 root root 48 Sep 11 19:30 processed/
test-suse:/tftpboot # ls -ld /tftpboot/
drwxrwxrwx 4 root root 680 Sep 11 19:30 /tftpboot/
test-suse:/tftpboot # pwd
/tftpboot
All the files have 666 perms
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 06:42 AM
09-11-2006 06:42 AM
Re: system command not working within CGI script
my $status = system("/usr/bin/mv /tftpboot/processed/* /tftpboot/");
Still get the same exit code
Back shortly
Thanks again
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 06:56 AM
09-11-2006 06:56 AM
Re: system command not working within CGI script
$status = system("xxx yyy");
print "Status = ",$status,"\n";
($a,$b,$c) = (getpwuid($<)) [0,2,3];
print "User: ",$a," UID ",$b," GID ",$c," EUID ",$<,"\n";
print "PATH: ",$ENV{PATH},"\n";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 07:54 AM
09-11-2006 07:54 AM
Re: system command not working within CGI script
We have
my $status = system("/usr/bin/mv /tftpboot/processed/* /tftpboot/");
print "Status = ",$status,"\n";
my ($a,$b,$c) = (getpwuid($<)) [0,2,3];
print "User: ",$a," UID ",$b," GID ",$c," EUID ",$<,"\n";
print "PATH: ",$ENV{PATH},"\n";
This displays
Status = 32512 User: daemon UID 2 GID 2 EUID 2 PATH: /usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin
I can move the files as the user daemon
TIA
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 07:59 AM
09-11-2006 07:59 AM
Re: system command not working within CGI script
Patrick was right. I added mv to /usr/bin/mv. Should have been /bin/mv
This now works
Will look at the perl script for the configUpload with the information supplied
TIA
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 08:05 AM
09-11-2006 08:05 AM
Re: system command not working within CGI script
The error output from the scripts is also in the apache error logs
marvellous, marvellous, marvellous
Thanks very much Patrick and Clay
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 08:14 AM
09-11-2006 08:14 AM
Re: system command not working within CGI script
The path '/bin' is a deprecated transition link to '/usr/bin'. You should be using '/usr/bin' and not '/bin'.
That aside, your checks for the return code are correct and are directly from the Perl documentation, so there is nothing wrong with the way you check the success or lack thereof of the system() call.
You might get a return code of <1> from 'mv' if there wasn't a source, for example.
You could avoid invoking the shell with your 'system()' call by passing multiple arguments, like:
# system("mv", (glob "/tftpboot/processed/*", "/tftpboot");
Regards!
...JRF...
- Tags:
- tlink
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 08:15 AM
09-11-2006 08:15 AM
Re: system command not working within CGI script
Sorry, a typo. That should be:
# system("mv", (glob "/tftpboot/processed/*"), "/tftpboot");
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 09:28 AM
09-11-2006 09:28 AM
Re: system command not working within CGI script
This is an "OLD" development server running suse 8.2, hence location of /bin
Thanks again
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 09:34 AM
09-11-2006 09:34 AM
Re: system command not working within CGI script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 12:59 PM
09-11-2006 12:59 PM
Re: system command not working within CGI script
Hey a Linux issue.
CGI scripts are normally run from a web browser. For security reasons all scripts run from an httpd session have little or no permissions and ability to do anything.
It has also been a standard practice for some years to chroot httpd servers to prevent exploits from having any power should they manage to chain a shell.
This approach works from the shell because it is supposed to.
if the server is not chrooted and you have sudo installed, and you have the environment set correctly this should work. But the above conditions make this a tough way to administer a system.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com