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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script errors.. help please

Status
Not open for further replies.

bubsgt95

Programmer
Feb 21, 2003
6
US
when i try to run a script.. im getting the following errors.. im not good with ssh.. so.. i need some help.

./change_passwd.pl: use: command not found
./change_passwd.pl: use: command not found
./change_passwd.pl: use: command not found
./change_passwd.pl: use: command not found
./change_passwd.pl: use: command not found
./change_passwd.pl: /[%>] $/: Is a directory
./change_passwd.pl: line 9: syntax error near unexpected token `<<U'
./change_passwd.pl: line 9: ` use constant USAGEMSG => <<USAGE;'

____________________________________________________________
here is the script


#!/usr/bin/perl
# file: change_passwd_ssh.pl
use strict;
use Net::Telnet;
use Getopt::Long;
use IO::pty;
use POSIX 'setsid';
use constant PROMPT => '/[%>] $/';
use constant USAGEMSG => <<USAGE;
Usage: change_passwd.pl [options] machine1, machine2, ...
Options:
--user <user> Login name
--old <pass> Current password
--new <pass> New password
USAGE
my ($USER,$OLD,$NEW);
die USAGEMSG unless GetOptions('user=s' => \$USER,
'old=s' => \$OLD,
'new=s' => \$NEW);
$USER ||= $ENV{LOGNAME};
$OLD or die &quot;provide current password with --old\n&quot;;
$NEW or die &quot;provide new password with --new\n&quot;;
change_passwd($_,$USER,$OLD,$NEW) foreach @ARGV;
sub change_passwd {
my ($host,$user,$oldpass,$newpass) = @_;
my $ssh = do_cmd('ssh',&quot;-l$user&quot;,$host)
or die &quot;couldn't launch ssh subprocess&quot;;
my $shell = Net::Telnet->new(Fhopen => $ssh);
$shell->binmode(1);
$shell->input_log('passwd.log') if DEBUG;
$shell->errmode('return');
$shell->waitfor('/password: /');
$shell->print($oldpass);
$shell->waitfor(PROMPT) or return &quot;host refused login: wrong password?\n&quot;;
$shell->print('passwd');
$shell->waitfor('/Old password:/') or return warn &quot;$host: &quot;,$shell->errmsg,&quot;\n&quot;;
$shell->print($oldpass);
my($pre,$match) = $shell->waitfor(Match => '/Incorrect password/',
Match => '/New password:/');
$match =~ /New/ or return warn &quot;$host: Incorrect password.\n&quot;;
$shell->print($newpass);
($pre,$match) = $shell->waitfor(Match => '/Bad password/',
Match => '/Re-enter new password:/');
$match =~ /Re-enter/ or return warn &quot;$host: New password rejected.\n&quot;;
$shell->print($newpass);
$shell->waitfor('/Password changed\./')
or return warn &quot;$host: &quot;,$shell->errmsg,&quot;\n&quot;;
print &quot;Password changed for $user on $host.\n&quot;;
}
sub do_cmd {
my ($cmd,@args) = @_;
my $pty = IO::pty->new or die &quot;can't make Pty: $!&quot;;
defined (my $child = fork) or die &quot;Can't fork: $!&quot;;
return $pty if $child;
setsid();
my $tty = $pty->slave;
close $pty;
STDIN->fdopen($tty,&quot;r&quot;) or die &quot;STDIN: $!&quot;;
STDOUT->fdopen($tty,&quot;w&quot;) or die &quot;STDOUT: $!&quot;;
STDERR->fdopen(\*STDOUT,&quot;w&quot;) or die &quot;STDERR: $!&quot;;
close $tty;
$| = 1;
exec $cmd,@args;
die &quot;Couldn't exec: $!&quot;;
}

 
Looks like the script is not being executed through perl. It looks like it is being interpreted by the shell as a list of commands, and obviously failing.

Maybe try:

#perl change_passwd.pl

Will. will@hellacool.co.uk
 
The #! line has to be the very first line in the file with no extra spaces. Check your character set carefully as well because # is one of those characters that can represent different bytes in different sets. On a unix box
[tt]od -xc script | head -2[/tt]
should yield
[tt]0000000 2123 752f 7273 622f 6e69 702f 7265 0a6c
# ! / u s r / b i n / p e r l \n[/tt]
where the [tt]2123[/tt] is the crucial bit.

Yours, &quot;As soon as we started programming, we found to our surprise that it wasn't as
easy to get programs right as we had thought. Debugging had to be discovered.
I can remember the exact instant when I realized that a large part of my life
from then on was going to be spent in finding mistakes in my own programs.&quot;
--Maurice Wilk
 
i moved the#! line over.. now i get a new error.
here below

Can't locate Net/Telnet.pm in @INC (@INC contains: /usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/lib/perl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl/5.6.0/i386-linux /usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl .) at ./change_passwd.pl line 4.
BEGIN failed--compilation aborted at ./change_passwd.pl line 4.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top