paulski82 has asked for the wisdom of the Perl Monks concerning the following question:
In summary, I need a portable way to test from inside my Perl script if the script was run using a login (su - <username>) vs non-login (su <username>) where the script is the shell of the user I'm trying to su to.
I can do this easily in C using the following code:
/* testsh2.c */ #include <stdlib.h> #include <stdio.h> int main(int argc, char** argv) { int i = 0; for (;i < argc; i++) { printf("argv[%d]: %s\n", i, argv[i]); } exit(0); }
Password file is as follows (this is a Red Hat Enterpise Linux 5 server). The /tmp/testsh2 is the C code above compiled.
root@aster /tmp# cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.8 (Tikanga) root@aster /tmp# cat /etc/passwd| grep paultest paultest:x:401:401::/home/paultest:/tmp/testsh2
Here's the output when I run the C program.
root@aster /tmp# su - paultest argv[0]: -testsh2 root@aster /tmp# su paultest argv[0]: testsh2
As you can see, I can just test if the first character argv[0] is a '-'.
I'm having trouble doing the same under Perl.
The variable $0 doesn't have a '-' at the start of it under Perl and the ARGV array doesn't have the program name as the first element like in C.
Is there any way to get this information under Perl?
NOTE: I have searched the archives for things like 'login shell', but there are too many hits, as you'd expect.
|
|---|