Ask a Question related to PERL Beginners, Design and Development.
-
Aman #1
How to su in a script if su needs a pswd ?
Hello,
I am running a command as part of my script on a Unix box for which I need
to su to a different username.
This su requires a password as well.
I could not find any option of passing the password in su.
Tried the shell script solution of here docs :
su <<TillEnd
admin
test
TillEnd
But even this does not work.
Could anyone please guide me how to su in a script (shell / perl) ?
I cannot have my username added to the /etc/sudoers to execute commands as
root...
Thanks in advance
-aman
Aman Guest
-
6.1 script not working on 7.0 server. Script used towork!
I've a problem with some coldfusion 6.1 scripts running on a server with coldfusion 7. It seems that it isn't accepting the hidden type for the tag... -
CF Grid / Java Script / Action Script
Hi, Does anyone know of a good reference for the attributes CFgrid exposes in a flash form? eg. I would like to select the first row on load. ... -
ksh script - Preventing multiple runs of a particular script
I am having trouble with a ksh script I am writing. I need to make sure that the script is not already running when it is kicked off in cron. ... -
Batch Script returns "Could Not Run script - File was not found"
I need to batch process some images to convert them to jpgs. When I try to set it up I get "Could Not Run script - File was not found". This also... -
Execute shell script from a perl script
Hi, How can I executed a Unix shell script from a Perl script. The shell script is a dump of a oracle table to a file. The perl script is for... -
James #2
RE: How to su in a script if su needs a pswd ?
> Hello,
Take a look at the Expect module. Here is some code from a script i did a
long time ago. It was a wrapper script for su. It may help:
--
use strict;
use Expect;
use IO:Socket;
# grab the user if entered
my $user = $ARGV[0] if $ARGV[0];
my $pw;
# might fail if it's su -
if ($user && $user !~ /root/) {
real_su();
}
# &real_su unless $user =~ /root/;
print "Password: ";
$pw = <STDIN>;
chomp $pw;
# send the captured password to be cyphered
cypher($pw);
# tunnel($string);
# now that we cypher and sent the pw to us go ahead and run the
&real_su();
sub real_su
{
my $su = Expect->spawn('/bin/su',$user) or die "Can't start Program:
$!\n";
# stop the output from going to STDOUT
$su->log_stdout(0);
# capture pw and die with appropriate string if pw is wrong
my $error = ($su->expect(10, 'password:'))[1];
if ($error)
{
print $su "Sorry.\r";
print STDOUT "Sorry.\r";
$su->soft_close();
}
print $su "$pw\r";
$su->soft_close();
exit 0;
}
........
James Guest
-
Randal #3
Re: How to su in a script if su needs a pswd ?
>>>>> "Aman" == Aman Thind <co.in> writes:
Aman> I am running a command as part of my script on a Unix box for which I need
Aman> to su to a different username.
Aman> This su requires a password as well.
A question just like this was posted to the Perl-Beginners Yahoo
mailing list.
If this was you, your question was already asked and answered,
and should not be re-asked in a different forum. You're wasting
valuable resources.
If it wasn't you, please look at the archives, located at
<http://groups.yahoo.com/group/perl-beginner/messages>, and search for
the subject lines similar to what you asked here.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Randal Guest
-
Wiggins #4
Re: How to su in a script if su needs a pswd ?
>
Can you 'setuid' the script that needs to be called with the special
privileges? Then shell out to that script for the processing it needs
to do...
I am not much of a setuid expert but this should work based on my
understanding of it.
http://danconia.org
Wiggins Guest
-
Aman #5
RE: How to su in a script if su needs a pswd ?
Hi James,
Thanks for the pointer to the Expect module.
I'll set it up and hope I get it working...else I'll come running back to
you :p
Can I establish an SSH connection and do something like Sshexec and Scp
tasks do in ant 1.6.x using Expect ?
Thanks
-aman
-----Original Message-----
From: Kipp, James [mailto:com]
Sent: 17 February 2004 19:35
To: 'Thind, Aman'; Perl Beginners
Subject: RE: How to su in a script if su needs a pswd ?
Take a look at the Expect module. Here is some code from a script i did a
long time ago. It was a wrapper script for su. It may help:
--
use strict;
use Expect;
use IO:Socket;
# grab the user if entered
my $user = $ARGV[0] if $ARGV[0];
my $pw;
# might fail if it's su -
if ($user && $user !~ /root/) {
real_su();
}
# &real_su unless $user =~ /root/;
print "Password: ";
$pw = <STDIN>;
chomp $pw;
# send the captured password to be cyphered
cypher($pw);
# tunnel($string);
# now that we cypher and sent the pw to us go ahead and run the
&real_su();
sub real_su
{
my $su = Expect->spawn('/bin/su',$user) or die "Can't start Program:
$!\n";
# stop the output from going to STDOUT
$su->log_stdout(0);
# capture pw and die with appropriate string if pw is wrong
my $error = ($su->expect(10, 'password:'))[1];
if ($error)
{
print $su "Sorry.\r";
print STDOUT "Sorry.\r";
$su->soft_close();
}
print $su "$pw\r";
$su->soft_close();
exit 0;
}
........
Aman Guest
-
Aman #6
RE: How to su in a script if su needs a pswd ?
Hello Randal,
In your -
If ( aman eq "same person who asked in a diff forum")
{
print "JERK";
}
Else
{
print "Valuable archive of answers to similar question" ;
}
I pass through the else block as you had earlier answered to one Joe
Catanzaro though his question was strikingly similar to mine.
One of the most valuable resources that I would be wasting by asking the
same question in diff forums for which I've already received the answer is
my own time !
Thanks for the link though...the discussion was enlightening indeed.
-aman
-----Original Message-----
From: com [mailto:com]
Sent: 17 February 2004 20:30
To: org
Subject: Re: How to su in a script if su needs a pswd ?
[/ref][/ref]
Aman> I am running a command as part of my script on a Unix box for which I
need
Aman> to su to a different username.
Aman> This su requires a password as well.
A question just like this was posted to the Perl-Beginners Yahoo
mailing list.
If this was you, your question was already asked and answered,
and should not be re-asked in a different forum. You're wasting
valuable resources.
If it wasn't you, please look at the archives, located at
<http://groups.yahoo.com/group/perl-beginner/messages>, and search for
the subject lines similar to what you asked here.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!
--
To unsubscribe, e-mail: org
For additional commands, e-mail: org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Aman Guest
-
Randal #7
Re: How to su in a script if su needs a pswd ?
>>>>> "Aman" == Thind, Aman <co.in> writes:
Aman> I pass through the else block as you had earlier answered to one Joe
Aman> Catanzaro though his question was strikingly similar to mine.
I just find it odd that nobody asks a question like that for at least
six months in my recollection, and then it pops up twice within two
days in two different similar forums. So shoot me. :)
More often than not, it's someone who is interested in wasting a lot
of free resources.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Randal Guest
-
Aman #8
RE: How to su in a script if su needs a pswd ?
:)
By the way your stress on avoiding to store the pswd in any readable disk
file really made me look at my problem and possible solutions from a whole
new perspective...
Cheers !
-aman
-----Original Message-----
From: com [mailto:com]
Sent: 17 February 2004 21:53
To: Thind, Aman
Cc: org
Subject: Re: How to su in a script if su needs a pswd ?
[/ref][/ref]
Aman> I pass through the else block as you had earlier answered to one Joe
Aman> Catanzaro though his question was strikingly similar to mine.
I just find it odd that nobody asks a question like that for at least
six months in my recollection, and then it pops up twice within two
days in two different similar forums. So shoot me. :)
More often than not, it's someone who is interested in wasting a lot
of free resources.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!
Aman Guest
-
Wiggins #9
RE: How to su in a script if su needs a pswd ?
Please bottom post....
You could, but in the case of SSH you would be better off using
Net::SSH::Perl or Net::SFTP. Expect should be an absolute last resort,
screen scraping is fine when there is no other published interface, in
the case of SSH that isn't the case.
http://danconia.org
>
> Take a look at the Expect module. Here is some code from a script i did a
> long time ago. It was a wrapper script for su. It may help:
> --
> use strict;
> use Expect;
> use IO:Socket;
>
> # grab the user if entered
> my $user = $ARGV[0] if $ARGV[0];
> my $pw;
>
> # might fail if it's su -
> if ($user && $user !~ /root/) {
> real_su();
> }
> # &real_su unless $user =~ /root/;
>
> print "Password: ";
> $pw = <STDIN>;
> chomp $pw;
>
> # send the captured password to be cyphered
> cypher($pw);
>
> # tunnel($string);
>
> # now that we cypher and sent the pw to us go ahead and run the
>
> &real_su();
>
>
> sub real_su
> {
>
> my $su = Expect->spawn('/bin/su',$user) or die "Can't start Program:
> $!\n";
> # stop the output from going to STDOUT
> $su->log_stdout(0);
> # capture pw and die with appropriate string if pw is wrong
> my $error = ($su->expect(10, 'password:'))[1];
> if ($error)
> {
> print $su "Sorry.\r";
> print STDOUT "Sorry.\r";
> $su->soft_close();
> }
> print $su "$pw\r";
> $su->soft_close();
> exit 0;
> }
>
> .......
>
>
>
> --
> To unsubscribe, e-mail: org
> For additional commands, e-mail: org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>[/ref]
Wiggins Guest



Reply With Quote

