Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie question, exec shell command in perl 2

Status
Not open for further replies.

entrylevel

Technical User
Nov 29, 2001
46
CA
in shell I can do
/usr/local/samba/bin/smbpasswd -s << EOF > /dev/null
$oldpasswd
$newpasswd
$verifypasswd
EOF

how to translate it to perl? simply add system seems does not work ...

system ("/usr/local/samba/bin/smbpasswd -s << EOF > /dev/null
$oldpasswd
$newpasswd
$verifypasswd
EOF
");

while $oldpasswd, $newpasswd, $verifypasswd are variables in perl. Thanks.

 
My knowledge is limited, someone may suggest a better way, but you might try something like this.

Here we call the cat program to display the variable values. Substitute cat accordingly.

Code:
#!/usr/bin/perl -w
use strict;

my $oldpasswd    = "oldpass";
my $newpasswd    = "newpass";
my $verifypasswd = "verpass";

open (PROG, "|/usr/bin/cat") or die ("can't open program");
print PROG <<EOF
$oldpasswd
$newpasswd
$verifypasswd
EOF
;

close (PROG);
 
Thanks for the post. one more question, how can I get rid of the output in perl? thanks.
 
in shell i can use redirect to /dev/null and there is no output, but in perl

#!/usr/bin/perl -w
use strict;
sub changesmbpasswd {
my $oldpasswd = "oldpass";
my $newpasswd = "newpass";
my $verifypasswd = "newpass";

open (PROG, "|/usr/local/samba/bin/smbpasswd -s") or die ("can't open program");
print PROG <<EOF
$oldpasswd
$newpasswd
$verifypasswd
EOF
;

close (PROG);
}
&changesmbpasswd

it alwasys has an output line,

"Password changed for user testuser"

how can I get rid of that output line inside perl script? Thanks.


 
same syntax as the shell as it happens

"|/usr/local/samba/bin/smbpasswd -s 2>&1"

Mike

I am not inscrutable. [orientalbow]

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
:) just realized I could do it that way. Thanks.

above code, if I declear $oldpasswd, $newpasswd, $verifypasswd outside of function changesmbpasswd, how can I pass the value into this function? still newbie, I know.

 
plus, when I call this function in a perl cgi script, it seems "print" and EOF do not work from there. how can I accomplish the same function in a cgi script not run directly from shell. Thanks.
 
re running in cgi script - first check the account that runs the cgi scripts - does it have the correct permissions to do that?

Mike

I am not inscrutable. [orientalbow]

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
everybody can execute the smbpasswd if I understood you correct.

the cgi script can be run successfully, just after adding this part (which can be used in the shell), nothing happened to samba password, the script just skipped this part, so i m thinking maybe there is different way to write it if I want to implement it over the browser. thanks for the suggestion.
 
ooh, I see your point, there is an option that I omitted, should be smbpasswd -U uid, thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top