perl script

Discussion in 'Perl Misc' started by yo, Jun 27, 2005.

  1. yo

    yo Guest

    I have a billing program that generates dynamic files in
    /usr/private/platypusd/config_files/pms.1234, where 12345 is a random
    number and never the same twice.

    This file contains some date separated by the pipe sign. Example:

    username|password.

    I have a perl script that is called by this billing program to parse
    the file pms.random# from the directory above. The perl script is as
    follows.

    #!/usr/bin/perl
    open(INFILE, "@ARGV[0]");
    $infile = <INFILE>;
    ($username,$password) = split(/\|/, $infile);
    close(INFILE);

    @calladduser = ("/usr/sbin/adduser -g 100 -d /home/sites/home/
    $password -s /sbin/nologin $username","\n");
    system("@calladduser");

    print ("New User $username has been successfully added!\n");
    print ("New User password: $password\n");
    print ("New User Home Directory: /home/sites/home/$username\n");

    open(OUTFILE,
    ">>/usr/local/private/platypusd/secure_dir/plat_adduser.log");
    print OUTFILE ("@calladduser");
    close(OUTFILE);

    I get an error of not such file or directory when the billing program
    calls this script to parse the file. I don't understand much about
    perl and I think the script is not looking for the file, maybe it
    doesn't know where the file to be parse is. I get an error of No such
    file or directory.

    I would appreciate if someone could help me on this. Thanks in
    advance.

    paul
     
    yo, Jun 27, 2005
    #1
    1. Advertising

  2. yo

    lynn Guest

    Hello paul,

    yo wrote:
    > I have a billing program that generates dynamic files in
    > /usr/private/platypusd/config_files/pms.1234, where 12345 is a random
    > number and never the same twice.

    (snipped)

    > #!/usr/bin/perl

    use strict;
    use warnings;

    These two lines need to be added to help you troubleshoot the problem.

    > open(INFILE, "@ARGV[0]");

    ^^^^^^^^^^^

    I don't think that is right. Should'nt that be $ARGV[0] also
    you need to check to see if that worked
    like:

    open (INFILE, "$ARGV[0]") or die "Can't open file $ARGV[0] $!\n"

    > $infile = <INFILE>;
    > ($username,$password) = split(/\|/, $infile);
    > close(INFILE);
    >
    > @calladduser = ("/usr/sbin/adduser -g 100 -d /home/sites/home/
    > $password -s /sbin/nologin $username","\n");
    > system("@calladduser");


    Same here check to see if the command ran correctly!

    system ("@calladduser") or die " call to add user failed $!\n"

    >
    > print ("New User $username has been successfully added!\n");
    > print ("New User password: $password\n");
    > print ("New User Home Directory: /home/sites/home/$username\n");
    >
    > open(OUTFILE,
    > ">>/usr/local/private/platypusd/secure_dir/plat_adduser.log");
    > print OUTFILE ("@calladduser");


    Same here!

    > close(OUTFILE);

    same here!
    >

    lynn
     
    lynn, Jun 27, 2005
    #2
    1. Advertising

  3. yo

    yo Guest

    I will try this right now lynn, thanks


    On Mon, 27 Jun 2005 07:34:43 -0700, "lynn" <> wrote:

    >Hello paul,
    >
    >yo wrote:
    >> I have a billing program that generates dynamic files in
    >> /usr/private/platypusd/config_files/pms.1234, where 12345 is a random
    >> number and never the same twice.

    >(snipped)
    >
    >> #!/usr/bin/perl

    >use strict;
    >use warnings;
    >
    >These two lines need to be added to help you troubleshoot the problem.
    >
    >> open(INFILE, "@ARGV[0]");

    > ^^^^^^^^^^^
    >
    >I don't think that is right. Should'nt that be $ARGV[0] also
    >you need to check to see if that worked
    >like:
    >
    >open (INFILE, "$ARGV[0]") or die "Can't open file $ARGV[0] $!\n"
    >
    >> $infile = <INFILE>;
    >> ($username,$password) = split(/\|/, $infile);
    >> close(INFILE);
    >>
    >> @calladduser = ("/usr/sbin/adduser -g 100 -d /home/sites/home/
    >> $password -s /sbin/nologin $username","\n");
    >> system("@calladduser");

    >
    >Same here check to see if the command ran correctly!
    >
    >system ("@calladduser") or die " call to add user failed $!\n"
    >
    >>
    >> print ("New User $username has been successfully added!\n");
    >> print ("New User password: $password\n");
    >> print ("New User Home Directory: /home/sites/home/$username\n");
    >>
    >> open(OUTFILE,
    >> ">>/usr/local/private/platypusd/secure_dir/plat_adduser.log");
    >> print OUTFILE ("@calladduser");

    >
    >Same here!
    >
    >> close(OUTFILE);

    >same here!
    >>

    >lynn
    >
     
    yo, Jun 27, 2005
    #3
  4. yo

    yo Guest

    I got some error using those commands any idea why the following is
    happening

    [root@test secure_dir]# ./plat_adduser
    bash: ./plat_adduser: No such file or directory


    [root@test secure_dir]# perl plat_adduser
    usage: adduser [-u uid [-o]] [-g group] [-G group,...]
    [-d home] [-s shell] [-c comment] [-m [-k template]]
    [-f inactive] [-e expire mm/dd/yy] [-p passwd] [-n]
    [-r] name
    adduser -D [-g group] [-b base] [-s shell] [-f inactive] [-e
    expire mm/dd/yy]
    New User has been successfully added!
    New User password:
    New User Home Directory: /home/sites/home/


    whats the difference between ./ and using perl to execute a perl
    script. ./ isnt working.


    On Mon, 27 Jun 2005 10:46:21 -0400, yo <> wrote:

    >
    >I will try this right now lynn, thanks
    >
    >
    >On Mon, 27 Jun 2005 07:34:43 -0700, "lynn" <> wrote:
    >
    >>Hello paul,
    >>
    >>yo wrote:
    >>> I have a billing program that generates dynamic files in
    >>> /usr/private/platypusd/config_files/pms.1234, where 12345 is a random
    >>> number and never the same twice.

    >>(snipped)
    >>
    >>> #!/usr/bin/perl

    >>use strict;
    >>use warnings;
    >>
    >>These two lines need to be added to help you troubleshoot the problem.
    >>
    >>> open(INFILE, "@ARGV[0]");

    >> ^^^^^^^^^^^
    >>
    >>I don't think that is right. Should'nt that be $ARGV[0] also
    >>you need to check to see if that worked
    >>like:
    >>
    >>open (INFILE, "$ARGV[0]") or die "Can't open file $ARGV[0] $!\n"
    >>
    >>> $infile = <INFILE>;
    >>> ($username,$password) = split(/\|/, $infile);
    >>> close(INFILE);
    >>>
    >>> @calladduser = ("/usr/sbin/adduser -g 100 -d /home/sites/home/
    >>> $password -s /sbin/nologin $username","\n");
    >>> system("@calladduser");

    >>
    >>Same here check to see if the command ran correctly!
    >>
    >>system ("@calladduser") or die " call to add user failed $!\n"
    >>
    >>>
    >>> print ("New User $username has been successfully added!\n");
    >>> print ("New User password: $password\n");
    >>> print ("New User Home Directory: /home/sites/home/$username\n");
    >>>
    >>> open(OUTFILE,
    >>> ">>/usr/local/private/platypusd/secure_dir/plat_adduser.log");
    >>> print OUTFILE ("@calladduser");

    >>
    >>Same here!
    >>
    >>> close(OUTFILE);

    >>same here!
    >>>

    >>lynn
    >>
     
    yo, Jun 27, 2005
    #4
  5. yo wrote:

    > I got some error using those commands


    What commands? Please place your responses in context.

    > any idea why the following is happening
    >
    > [root@test secure_dir]# ./plat_adduser
    > bash: ./plat_adduser: No such file or directory


    > [root@test secure_dir]# perl plat_adduser

    (not an error)

    > whats the difference between ./ and using perl to execute a perl
    > script. ./ isnt working.


    Just executing the script will look for the interpreter in the location
    specified in shebang line (#!).

    Specifiying 'perl' will look for program 'perl' in the directories
    listed in the evironment variable PATH.

    >>>>#!/usr/bin/perl


    So either perl is installed soemwhere other than /usr/bin or there's an
    invisible character on the end of that line.
     
    Brian McCauley, Jun 27, 2005
    #5
  6. yo

    s. keeling Guest

    yo <>:
    >
    > [snip]
    > [root@test secure_dir]# perl plat_adduser
    > usage: adduser [-u uid [-o]] [-g group] [-G group,...]
    > [-d home] [-s shell] [-c comment] [-m [-k template]]
    > [-f inactive] [-e expire mm/dd/yy] [-p passwd] [-n]
    > [-r] name
    > adduser -D [-g group] [-b base] [-s shell] [-f inactive] [-e
    > expire mm/dd/yy]
    > New User has been successfully added!


    Bizarre. man adduser.

    > whats the difference between ./ and using perl to execute a perl
    > script. ./ isnt working.


    Likely you haven't turned on execute bits on the file. "ls -l
    plat_adduser" should show something like:

    -rw-r--r-- ...

    meaning it's not excutable (and that's off-topic). man chmod (eg.,
    "chmod 744 plat_adduser" or "chmod u+x plat_adduser").


    --
    Any technology distinguishable from magic is insufficiently advanced.
    (*) http://www.spots.ab.ca/~keeling Linux Counter #80292
    - - Spammers! http://www.spots.ab.ca/~keeling/autospam.html
    http://www.ietf.org/rfc/rfc1855.txt democracy human rights Taiwan Independence
     
    s. keeling, Jun 27, 2005
    #6
  7. yo

    yo Guest

    weird once i copied the contents of that script to a new file it
    started working with ./ and using perl on the command line. thanks for
    all the help.

    On Mon, 27 Jun 2005 10:12:00 -0400, yo <> wrote:

    >I have a billing program that generates dynamic files in
    >/usr/private/platypusd/config_files/pms.1234, where 12345 is a random
    >number and never the same twice.
    >
    >This file contains some date separated by the pipe sign. Example:
    >
    >username|password.
    >
    >I have a perl script that is called by this billing program to parse
    >the file pms.random# from the directory above. The perl script is as
    >follows.
    >
    >#!/usr/bin/perl
    >open(INFILE, "@ARGV[0]");
    > $infile = <INFILE>;
    > ($username,$password) = split(/\|/, $infile);
    >close(INFILE);
    >
    >@calladduser = ("/usr/sbin/adduser -g 100 -d /home/sites/home/
    >$password -s /sbin/nologin $username","\n");
    >system("@calladduser");
    >
    >print ("New User $username has been successfully added!\n");
    >print ("New User password: $password\n");
    >print ("New User Home Directory: /home/sites/home/$username\n");
    >
    >open(OUTFILE,
    >">>/usr/local/private/platypusd/secure_dir/plat_adduser.log");
    > print OUTFILE ("@calladduser");
    >close(OUTFILE);
    >
    >I get an error of not such file or directory when the billing program
    >calls this script to parse the file. I don't understand much about
    >perl and I think the script is not looking for the file, maybe it
    >doesn't know where the file to be parse is. I get an error of No such
    >file or directory.
    >
    >I would appreciate if someone could help me on this. Thanks in
    >advance.
    >
    >paul
     
    yo, Jun 27, 2005
    #7
  8. yo <> wrote:

    > Subject: perl script



    Please put the subject of your article in the Subject of your article.


    > open(INFILE, "@ARGV[0]");



    You should always enable warnings when developing Perl code!

    You should always, yes *always*, check the return value from open().

    open(INFILE, $ARGV[0] ) or die "could not open '$ARGV[0]' $!";


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jun 27, 2005
    #8
  9. yo

    Joe Smith Guest

    lynn wrote:

    > open (INFILE, "$ARGV[0]") or die "Can't open file $ARGV[0] $!\n"


    Do not abuse double quotes like that.
    open INFILE,$ARGV[0] or die "Can't open file $ARGV[0] $!\n"
    or
    $file = shift;
    open INFILE,$file or die "Can't open file $file $!\n"

    > Same here check to see if the command ran correctly!
    >
    > system ("@calladduser") or die " call to add user failed $!\n"


    No.
    1) system("@calladduser") operates differently from
    system(@calladduser) if the array contains shell metacharacters.
    2) system() returns the error code, which is true when there
    was an error and false when no error.
    3) For system(), use $? instead of $!.

    system @calladduser and die "Error code $? from @calladduser\n";
    or
    system @calladduser == 0 or die "Error code $? from @calladduser\n";

    -Joe
     
    Joe Smith, Jun 28, 2005
    #9
  10. Tim Hammerquist <> writes:

    > You probably meant:
    >
    > open(INFILE, $ARGV[0]) or die "can't open $ARGV[0]";


    Even better, explain *why* the file can't be opened:

    open(INFILE, $ARGV[0]) or die "Can't open $ARGV[0]: $!";

    sherm--

    --
    Due to the amount of unreadable gibberish being posted from Google Groups,
    I seldom read messages posted from there.

    Cocoa/Perl: http://camelbones.sf.net Hire Me: http://www.dot-app.org
     
    Sherm Pendley, Jun 28, 2005
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wet Basement
    Replies:
    1
    Views:
    2,545
    BobMonk
    Jul 15, 2003
  2. dpackwood
    Replies:
    3
    Views:
    1,832
  3. pj
    Replies:
    3
    Views:
    302
  4. Petterson Mikael

    Execute another perl script from my perl script

    Petterson Mikael, Jan 5, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    148
    Paul Lalli
    Jan 5, 2005
  5. Replies:
    20
    Views:
    783
    Gunnar Hjalmarsson
    Jan 18, 2005
Loading...

Share This Page