Solved

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

Posted on 2010-11-27
9
1,170 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
  • 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 76

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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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 76

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PowerShell Special Characters In Text String 3 104
PowerShell Get-Help 10 59
Image not there 4 34
Solaris 4.1.3 cloning and booting 13 35
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…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now