Solved

Simplify scp & unix2dos to a single command : Shell script Perl

Posted on 2010-11-27
9
1,191 Views
Last Modified: 2012-06-21
I currently need to do transfer files from Linux RHES 4.x box to a remote
Windows 2003 box (running OpenSsh server) & would like to simplify
the following multi-step commands to a single step (using pipe | & redirection
or possibly using Perl if possible).  I would like to avoid creating a temp
file & having to remove the file after that

file.txt is the local file in my Linux box which has every line/record
that ends with <LF> character only but at the remote Windows server
end, we need the file copied to the Windows to be terminated with
<LF> plus <CR>


Put without Append
================
cat file.txt | unix2dos > tmpfile; scp tmpfile remoteid@Wintelhost:/c/temp/file.txt; rm -f tmpfile

Put with Append
==============
scp remoteid@Wintellhost:/c/temp/file.txt tmpfile; dos2unix tmpfile; cat file.txt >> tmpfile; unix2dos tmpfile; scp tmpfile remoteid@Wintellhost:/c/temp/file.txt; rm -f tmpfile

0
Comment
Question by:sunhux
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 20

Accepted Solution

by:
edster9999 earned 167 total points
ID: 34222911
You can get rid of the temp file by piping the command directly to the other box.
SCP doesn't let you do this (as you have probably already worked out)
but you could use SSH to run a command on the other box and get that to write the file from the pipe.
I use this on Linux / unix machines.  I have never tested it in windows land but it theory it should work.

Something like  :

cat file.txt | unix2dos | ssh remoteid@Wintelhost 'cat > /c/temp/file.txt'




0
 
LVL 78

Assisted Solution

by:arnold
arnold earned 167 total points
ID: 34223154
since this is a script, what is the issue with the added steps that the script will perform?

If you have a cygwin environment on the windows side, you could establish an SSH tunnel and then pipe the filename, file contents through the pipe to an application on the remote side that will get the filename and pipe the data through while replacing the <lf> with <cr>.

0
 
LVL 28

Assisted Solution

by:FishMonger
FishMonger earned 166 total points
ID: 34224136
When I see questions such as yours, I interpret as "how can I combine x number of steps/commands into 1 and still know that everything was successful without ever having to deal with error checking/handling?"

The answer is "You can't".

Do yourself a favor and write a full script.  Your first decision is 'do "I" want to use a shell script or a Perl script'?

If you use a Perl script, you there are at least 3 modules available that can properly transfer the file without first having to create a temp.
Net::FTP
Net::SFTP
Net::SSH2
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sunhux
ID: 34224831
I can't implement cygwin environment as the Windows side belongs to a strict &
unyielding customer



The links below appear wonderful, do you have specific example using the Perl
tool below to implement Ascii & Append modes

Net::SFTP
Net::SSH2
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 34225609
Currently, I don't have any example scripts and I won't be able to do any testing until I get back to work in a couple days.

>> the Windows side belongs to a strict & unyielding customer

Is the customer going to allow you to install the required Perl modules?

What version of perl is on the target server and is it a 32bit or 64bit build?  Some of the modules may not be available for the 64bit platform.
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 34225635
You can disregard my comment about needing to install the modules on the Windows server.  I forgot that you are going from Linux to Windows, not the other way around.
0
 
LVL 78

Expert Comment

by:arnold
ID: 34226398
IMHO, in order to combine the functionality of three individual steps that work into a single complex script seems like a strange and unnecessary.

When you scp files directly, what is the impact on the windows side?

Which ssh server are they running?
0
 

Author Comment

by:sunhux
ID: 34246007

Windows side is running Openssh server 3.8-1 :
some impacts of directly scp'ing directly : we may overwrite an existing file
at remote end : yes, good point that a multi-step script makes more sense
0
 

Author Closing Comment

by:sunhux
ID: 34343980
Thanks
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question