|
Author |
Message |
Peter
Team Member


Joined: 09 Jan 2002
Posts: 147
Location: UK
|
Posted:
Sun Jul 07, 2002 9:14 pm (22 years, 9 months ago) |
  |
What does the $< mean in the following code? I'm no expert at Perl but I'm trying to understand how the code, of which this is a part, works.
Code: | #!/usr/local/bin/perl
# restart
if ($< == 0) {
$usr = $ARGV[0];
} else {
$usr = (getpwuid($<))[0];
} |
|
________________________________ Maple Design - quality web design and custom programming |
|
       |
 |
Jos
Ex Team Member


Joined: 08 Jan 2002
Posts: 36
Location: The Netherlands
|
Posted:
Mon Jul 08, 2002 6:03 am (22 years, 9 months ago) |
  |
Peter wrote: | What does the $< mean in the following code? I'm no expert at Perl but I'm trying to understand how the code, of which this is a part, works.
Code: | #!/usr/local/bin/perl
# restart
if ($< == 0) {
$usr = $ARGV[0];
} else {
$usr = (getpwuid($<))[0];
} |
|
Is the Effective UID for the perl script.
Check to print this in a script like
print " UID = $< "\n;
$> can be use for setting the UID of the script like:
$> = 2000; |
________________________________ Jos
** Team Member ** http://www.josvanras.com ** |
|
     |
 |
Peter
Team Member


Joined: 09 Jan 2002
Posts: 147
Location: UK
|
Posted:
Mon Jul 08, 2002 7:30 am (22 years, 9 months ago) |
  |
Thanks Jos. You see, I have the following script on my server called restart_apache, which I run whenever I want to restart apache:
Code: | #!/usr/local/bin/perl
# restart
if ($< == 0) {
$usr = $ARGV[0];
} else {
$usr = (getpwuid($<))[0];
}
print "Restarting apache for $usr ...\n";
$pscmd = "ps -auxww";
open(PS, "$pscmd|") || die "can't run $pscmd: $!";
$title = <PS>; # eat the title off ps
while($cand = <PS>) {
chop($cand);
($user, $pid, $pcpu, $pmem, $vsz, $rss, $tt, $stat, $started, $time, $command)
= split(' ', $cand);
if ($user eq $usr && ($command =~ /http/ || $command =~ /^Master:/ || $command =~ /^Child:/) ) {
`kill $pid`;
}
} |
I've been trying to run this script via an exec call in a PHP web page (I'm attempting to build a nice web-based control panel for my server) and the script gets as far as printing "Restarting apache for reywob" and then it doesn't appear to get any further, as the "kill xxxx" commands don't get printed to the output.
Any ideas?
Thanks |
________________________________ Maple Design - quality web design and custom programming |
|
       |
 |
drathbun
WebHelper

Joined: 01 Mar 2003
Posts: 69
Location: Texas
|
Posted:
Tue Mar 04, 2003 4:27 am (22 years, 1 month ago) |
  |
Peter wrote: | I've been trying to run this script via an exec call in a PHP web page (I'm attempting to build a nice web-based control panel for my server) and the script gets as far as printing "Restarting apache for reywob" and then it doesn't appear to get any further, as the "kill xxxx" commands don't get printed to the output.
Any ideas? |
Okay, I realize that this is a really old post...
Did you consider that once you restart apache your session isn't valid any more? How are you going to get communications back to a web page when the system responsible for serving that data (apache) isn't there?
Or am I just confused about what you're trying to do. Or - since this post is ages old anyway - who cares...
Dave |
________________________________ Dave
Photography Site :: Query Tools Forum :: Weekend Fun |
|
     |
 |
Peter
Team Member


Joined: 09 Jan 2002
Posts: 147
Location: UK
|
Posted:
Tue Mar 04, 2003 8:35 am (22 years, 1 month ago) |
  |
drathbun wrote: | Okay, I realize that this is a really old post...
Did you consider that once you restart apache your session isn't valid any more? How are you going to get communications back to a web page when the system responsible for serving that data (apache) isn't there? |
Nope, I forgot all about that
Anyhow, I've moved off that server now, so whether it's possible or not doesn't matter any more - but thanks for pointing it out, I'm glad to have learned why it wouldn't work!
Peter |
________________________________ Maple Design - quality web design and custom programming |
|
       |
 |
drathbun
WebHelper

Joined: 01 Mar 2003
Posts: 69
Location: Texas
|
Posted:
Tue Mar 04, 2003 6:05 pm (22 years, 1 month ago) |
  |
|
     |
 |
|
|
You cannot post new topics in this forum. You cannot reply to topics in this forum. You cannot edit your posts in this forum. You cannot delete your posts in this forum. You cannot vote in polls in this forum.
|
Page generation time: 0.133772 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0
© 2001, 2002 phpBB Group :: Based on an FI Theme
| |