The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl from bash script arsidh Shell Programming and Scripting 10 06-04-2008 12:25 PM
Another bash shell to perl conversion freak UNIX for Dummies Questions & Answers 6 05-29-2008 01:04 PM
Comp-3 conversion possible with Shell Scripting or PERL? dfran1972 Shell Programming and Scripting 13 02-23-2008 07:51 PM
Perl conversion & perldoc question thumper Shell Programming and Scripting 2 09-11-2005 09:24 PM
Conversion of bash parsing script to perl? cstovall Shell Programming and Scripting 2 10-13-2004 10:33 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-12-2006
thumper thumper is offline VIP Member  
Supporter
  
 

Join Date: Feb 2005
Posts: 49
bash to perl conversion

I am trying to convert the following two lines of a bash script
to perl.

#start gnetcat on backup server
gnetcat -l -vv -p 2011 >$STORAGE_FILEPATH$DAY/$SHORT_NAME.$timestamp.tar

#start backup on client
ssh $SHORT_NAME sudo tar -cvf - --exclude=/dev --exclude=/lost+found --exclude=/proc / |netcat -w 2 -c troll 2011



The first line starting gnetcat on the backup seerver works fine, however I have not been able to get the second line, sent to the client, to work.

#start gnetcat on backup server
system `gnetcat -l -vv -p 2011`, ">", "$filename";
#start backup on client
system `ssh $SHORT_NAME sudo tar -cvf - --exclude=/dev --exclude=/lost+found --exclude=/proc --exclude=/db / |netcat -w 4 -c troll 2011`;

Any help pointing out what I am doing wrong is greatly appreciated.
  #2 (permalink)  
Old 07-12-2006
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
What do you exactly mean by "not work"? Normally, does the shell script prompt you password for ssh (or you bypass it based on "authorized_keys")?

I don't think you can use backticks in Perl if ssh gives a password prompt on connect. It may be fine for telnet or the like but likely to fail for ssh.

You may also try the more "native" Perl way of doing it -- use Perl modules for SSH. Note that you need to install that module if you intend to use it. A C compiler may be needed for installation. Given so many dependencies the easiest way of installing is by "cpan".

http://search.cpan.org/~dbrobins/Net...et/SSH/Perl.pm
  #3 (permalink)  
Old 07-14-2006
thumper thumper is offline VIP Member  
Supporter
  
 

Join Date: Feb 2005
Posts: 49
Quote:
"What do you exactly mean by "not work"? Normally, does the shell script prompt you password for ssh (or you bypass it based on "authorized_keys")?"
By not working I meant that the client machine apparently never received the tar command, the problem was not ssh based, the code was working as a bash script, it was just the transition from bash to perl that was giving me problems.

Quote:
"I don't think you can use backticks in Perl if ssh gives a password prompt on connect. It may be fine for telnet or the like but likely to fail for ssh."
You were right about not using the backticks, the code I finally wound up with that worked is
Code:
system "ssh", $SHORT_NAME, "sudo", "tar", "cvf", "-", "--exclude=/dev", "--exclude=/lost+found", "--exclude=/proc" ,  "/|", "netcat", "-w2", "-c", "troll", "2011" ;
In researching using ssh via the system call I learned that quoting the entire command in one set of double quotes sends the command as a single string, instead of as a command with arguments. Each command and each argument has to be defined by enclosing them in double quotes separated by a comma. The part that took the most head scratching was the "/|". The / is part of the tar command that essentially sends the output to STDOUT. The pipe then sends it to netcat. However for the / and | to be recognized as sending the STDOUT to a pipe they have to be placed together as a unit enclosed in quotes.

Quote:
"You may also try the more "native" Perl way of doing it -- use Perl modules for SSH. Note that you need to install that module if you intend to use it. A C compiler may be needed for installation. Given so many dependencies the easiest way of installing is by "cpan"."
It appeared to be such a small task, only two lines of code, that it didnt seem appropriate to use a module. Oh well, I did learn a fair amount about using system calls with ssh.

To cbkihong: Thanks for the reply, it got me pointed in the right direction to figure out what the problem was.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0