4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 Perl: What does this construct mean?
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
Peter
Team Member



Joined: 09 Jan 2002
Posts: 147
Location: UK

PostPosted: Sun Jul 07, 2002 9:14 pm (15 years, 4 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by PeterSend Personal MessageVisit Poster's WebsiteYahoo MessengerICQ Number
Jos
Ex Team Member



Joined: 08 Jan 2002
Posts: 36
Location: The Netherlands

PostPosted: Mon Jul 08, 2002 6:03 am (15 years, 4 months ago) Reply with QuoteBack to Top

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 **
OfflineView User's ProfileFind all posts by JosSend Personal MessageVisit Poster's Website
Peter
Team Member



Joined: 09 Jan 2002
Posts: 147
Location: UK

PostPosted: Mon Jul 08, 2002 7:30 am (15 years, 4 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by PeterSend Personal MessageVisit Poster's WebsiteYahoo MessengerICQ Number
drathbun
WebHelper
WebHelper


Joined: 01 Mar 2003
Posts: 69
Location: Texas

PostPosted: Tue Mar 04, 2003 4:27 am (14 years, 8 months ago) Reply with QuoteBack to Top

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... Rolling Eyes

Dave

________________________________
Dave
Photography Site :: Query Tools Forum :: Weekend Fun
OfflineView User's ProfileFind all posts by drathbunSend Personal MessageVisit Poster's Website
Peter
Team Member



Joined: 09 Jan 2002
Posts: 147
Location: UK

PostPosted: Tue Mar 04, 2003 8:35 am (14 years, 8 months ago) Reply with QuoteBack to Top

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 Shocked

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
OfflineView User's ProfileFind all posts by PeterSend Personal MessageVisit Poster's WebsiteYahoo MessengerICQ Number
drathbun
WebHelper
WebHelper


Joined: 01 Mar 2003
Posts: 69
Location: Texas

PostPosted: Tue Mar 04, 2003 6:05 pm (14 years, 8 months ago) Reply with QuoteBack to Top

Peter wrote:
Nope, I forgot all about that Shocked

It's alwalys the simple things that bite you... Laughing

Dave

________________________________
Dave
Photography Site :: Query Tools Forum :: Weekend Fun
OfflineView User's ProfileFind all posts by drathbunSend Personal MessageVisit Poster's Website
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




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.055745 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme