Sorry for having to reply from a Gates-based system, it is all I have access to at work)...
Remember that perl has a nasty feature of automatically instantiating any hash entry referenced in a test. In other words,
if( $ENV{ 'USERADMIN_USER' } ) {
will cause the USERADMIN_USER entry in the %ENV hash to come into being with a null or undefined value, even if it did NOT exist prior to the test. In some perl's even the following does not keep it from being instantiated,
if ( defined($ENV{ 'USERADMIN_USER' } ) && $ENV{ 'USERADMIN_USER' } ) {
I repeatedly have to keep in mind to do things like,
if ( defined($ENV{ 'USERADMIN_USER' } ) ) {
if ( $ENV{ 'USERADMIN_USER' } ) {
to keep this from happening. Of course, if you only check "true" values then it should not make any difference. Also, the environment variables created, removed or modified using the %ENV hash are visible to any child process spawned by the perl script that modified them.
------------------------
Remember, CM and QA are firstly attitude, secondly process, and only then tools...
-Ben Weatherall
-----Original Message-----
From:
plug-discuss-admin@lists.plug.phoenix.az.us
[
mailto:plug-discuss-admin@lists.plug.phoenix.az.us]On Behalf Of
der.hans
Sent: Friday, February 11, 2005 2:05 AM
To:
plug-discuss@lists.plug.phoenix.az.us
Subject: Re: shell script problem so simple I'm embarassed to ask
Am 11. Feb, 2005 schwätzte Craig White so:
> On Fri, 2005-02-11 at 00:43 -0700, Craig White wrote:
> > On Thu, 2005-02-10 at 23:44 -0700, der.hans wrote:
>
> > So the problems that were manifest - I have a number of variables passed
> > to my shell script from Webmin - values of which are obtained by adding
> > a line '/bin/env > /tmp/env.txt' in my shell script.
> >
> > The value of LDAPADMIN_USER must be passed from the shell script to the
> > perl script so that it deletes the right mailbox. I have tested each
> > step by declaring the value of LDAPADMIN_USER at the start of each shell
> > script and then comment it out to test it from within Webmin.
> >
> > The biggest problem I have now is returning the value of 'success' to
> > perl based Webmin. If you can tell me how to do that, I would be ever
> > grateful....I am working with 'return 0' but that isn't making Webmin
> > happy.
> ----
> OK - I got this worked out - no return values need to be supplied, the
> execution must be perfect and that's fine.
>
> I should admit that after every successful mailbox delete, I re-create
> it so that it shouldn't fail just because it doesn't exist.
>
> I still can't get variable passed from shell script to perl script.
>
> If I run this perl script - first uncommenting the variable
> USERADMIN_USER it runs fine.
>
> #! /usr/bin/perl -w
>
> #my $USERADMIN_USER='test2';
# Perl keeps environmental variables in the $ENV hash.
my $USERADMIN_USER = $ENV{ 'USERADMIN_USER' };
# Better yet:
# if( $ENV{ 'USERADMIN_USER' } ) {
# my $USERADMIN_USER = $ENV{ 'USERADMIN_USER' };
# } else {
# # print "Throw an error\n";
# # exit 1; # Throw a fit.
# }
# BTW, this is really a good example of something for the devel list ;-).
ciao,
der.hans
>
> use Cyrus::IMAP::Admin;
>
> $imap = Cyrus::IMAP::Admin->new("localhost")
> or die "Failed to connect";
> $imap->authenticate("-user" => "cyrus",
> "-password" => "PASSWD",
> "-mechanism" => "LOGIN")
> or die "Failed to authenticate";
> $imap->setacl("user.$USERADMIN_USER", "cyrus" => "+c");
> $imap->delete("user.$USERADMIN_USER");
> die $imap->error if $imap->error;
>
> but if I comment out the assignment of the USERADMIN_USER variable so it
> is passed from calling script, it apparently is never passed...
>
> # cat ldap_useradmin.after
> #!/bin/sh
>
> USERADMIN_ACTION="DELETE_USER"
> USERADMIN_USER="test2"
> #export USERADMIN_USER
>
> if [ "${USERADMIN_ACTION}" = "ADD_USER" ]; then
> /root/scripts/ldap_useradmin.addabook
> fi
>
> if [ "${USERADMIN_ACTION}" = "DELETE_USER" ]; then
> /root/scripts/ldap_useradmin.delmail.pl
> fi
>
> and this experiment shows the 'export USERADMIN_USER' line commented out
> but the result is the same whether it is or isn't commented...
>
> # ./ldap_useradmin.after
> Use of uninitialized value in concatenation (.) or string
> at /root/scripts/ldap_useradmin.delmail.pl line 13.
> Use of uninitialized value in concatenation (.) or string
> at /root/scripts/ldap_useradmin.delmail.pl line 14.
> Mailbox does not exist at /root/scripts/ldap_useradmin.delmail.pl line
> 15.
>
> now if I run ldap_useradmin.delmail.pl by itself
>
> # ./ldap_useradmin.delmail.pl
> Use of uninitialized value in concatenation (.) or string
> at ./ldap_useradmin.delmail.pl line 13.
> Use of uninitialized value in concatenation (.) or string
> at ./ldap_useradmin.delmail.pl line 14.
> Mailbox does not exist at ./ldap_useradmin.delmail.pl line 15.
>
> same results - but if I remove the comment from the line my
>
> #my $USERADMIN_USER='test2';
> and then run it again it is happy.
>
> # ./ldap_useradmin.delmail.pl
> [root@linuxserver scripts]#
>
> and of course, mailbox is deleted
>
> I find it incredibly frustrating to trace the problems - this clearly
> indicates to me that variable USERADMIN_USER doesn't get passed from the
> shell script ldap_useradmin.after to the perl script
> ldap_useradmin.delmail.pl
>
> Lemme see now, I've only put in like 6 hours on these 2 short scripts
> and the other 2 extremely short shell scripts that are working fine.
>
> ARRGH!!!
>
> Craig
>
>
>
> ---------------------------------------------------
> PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
> To subscribe, unsubscribe, or to change you mail settings:
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
>
--
# https://www.LuftHans.com/ http://www.AZOTO.org/
# If you're not learning, you're not living. - der.hans
---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss
---------------------------------------------------
PLUG-discuss mailing list -
PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss