perl script

Y

yo

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
 
L

lynn

Hello paul,
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
 
Y

yo

I will try this right now lynn, thanks


Hello paul,
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
 
Y

yo

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.


I will try this right now lynn, thanks


Hello paul,
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
 
B

Brian McCauley

yo said:
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.

So either perl is installed soemwhere other than /usr/bin or there's an
invisible character on the end of that line.
 
S

s. keeling

yo said:
[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").
 
Y

yo

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.
 
T

Tad McClellan

yo said:
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]' $!";
 
J

Joe Smith

lynn said:
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
 
S

Sherm Pendley

Tim Hammerquist said:
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--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top