CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Trying to use Net::SSH::Expect

 



tprizler
Novice

Jul 16, 2008, 8:16 AM

Post #1 of 5 (1327 views)
Trying to use Net::SSH::Expect Can't Post

Hi,

I am trying to use Net::SSH::Expect.

Basically I had success login into a remote server using this module.

The thing is i think i have a syntax problem...

I am logging into a remote server using ssh and trying to edit a file so this is waht i do:

$ssh->exec("sed 's/\/user/\#\/user/' /etc/auto.master > /etc/auto.master.new");
$ssh->exec("rm -fr /etc/auto.master");
$ssh->exec("mv /etc/auto.master.new /etc/auto.master");


for some reason the first line (sed) fails, and i don't know why,,,


Any one has an idea??

Thanks!


meloyelo
User

Jul 16, 2008, 8:53 AM

Post #2 of 5 (1326 views)
Re: [tprizler] Trying to use Net::SSH::Expect [In reply to] Can't Post

You need to double (or perhaps even triple) escape the backslashes.

Once because they are in double-quotes.
Once because they are getting interpreted by a shell.

Or - just save yourself the headache and change the quotes for the regex:


Code
$ssh->exec("sed 's,/user,#/user,' /etc/auto.master > /etc/auto.master.new");


There is no need to escape the # in the regex.

Note: we are telling sed to use different regex delimiters.


(This post was edited by meloyelo on Jul 16, 2008, 8:54 AM)


tprizler
Novice

Jul 17, 2008, 12:01 AM

Post #3 of 5 (1300 views)
Re: [meloyelo] Trying to use Net::SSH::Expect [In reply to] Can't Post

That worked!!!

I didn't knew I can do that..didn't knew the option.



Thanks!!!!!!!


tprizler
Novice

Jul 21, 2008, 5:50 AM

Post #4 of 5 (1116 views)
Re: [meloyelo] Trying to use Net::SSH::Expect [In reply to] Can't Post

Just wanted to ask you,

The commas are an option you can use on SED command? or it is General when you use regex??

The commas remove the need to escape so why don't use them all the time instead of slashes??

Thanks again!



KevinR
Veteran


Jul 21, 2008, 10:14 AM

Post #5 of 5 (1111 views)
Re: [tprizler] Trying to use Net::SSH::Expect [In reply to] Can't Post

its a general feature of regexps. Perl allows you to use different delimiters with the various quoting operators. The default delimiter in a regexp is a forward slash / but you can use a different one as long as you put the regexp operator letter in front of the regexp:

s#...#...#
m{....}

note that if you use a symbol that is a pair, like () and {} and [] you must use the left bracket and the right brackets.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives