Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: subroutine For ssh

by GHMON (Novice)
on Oct 09, 2019 at 05:15 UTC ( #11107228=note: print w/replies, xml ) Need Help??

in reply to subroutine For ssh


TNX for all comments

it was ok with this type

sub SSHApp { my ($MyIP , $MyUser , $MyPass , $MyPass2 , $command ) = @_ ; #SSH Connection to Applaince my $ssh_1 = Net::Appliance::Session->new({personality => 'ios', tr +ansport => 'SSH', host => "$MyIP",}) ; $ssh_1->connect({ username => "$MyUser", password => "$MyPass" + }) ; $ssh_1->begin_privileged({ password => "$MyPass2"}) ; print $ssh_1->cmd("$command") ; $ssh_1->end_privileged ; $ssh_1->close; }

Replies are listed 'Best First'.
Re^2: subroutine For ssh
by Fletch (Bishop) on Oct 09, 2019 at 13:34 UTC

    Couple of style nits:

    It's not necessary to requote everything as you've done in several places (e.g. "$MyUser" or "$command"). It's extra, unneeded visual noise and (in weird corner cases) could trigger behavior you don't intend (quoting something which has stringification overloaded; alternately if down the road the underlying API expects a HASHREF for an argument where it used to expect a SCALAR you've now got to go through and remove them).

    And more of a personal preference but WRT your variable naming, the "My" prefix on everything doesn't really gain you anything. Were you to keep it it's more common to use lowercase underscore delimited local lexical variable names rather than CamelCase (e.g. $unprivileged_password or $privileged_password might be better than $MyPass and $MyPass2).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11107228]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2023-09-22 08:33 GMT
Find Nodes?
    Voting Booth?

    No recent polls found