Solved

Linux Shell Script for copy file

Posted on 2014-09-16
3
440 Views
Last Modified: 2014-09-16
I am new to Linux Shell Script. With help from my previous posting, i was able to get a sample code from an expert.

My requirement is to call the .sh file from .Net Application. My Application will pass SourceFilePath and DestinationFilePath as Paramaters.

I expect Shell Script to get the parameters as Input and Copy/Paste the file.

How to customize my sample code with Parameters in it ?


#vim script.sh
echo "\home\testuser\file.csv"
read a
echo "\home\admin\user2\data\file.csv"
read b
echo "Data will be moving from $a to $b"
mv $a  $b
echo "Moving done"

:wq

#chmod u+x script.sh
#./script.sh

Open in new window

0
Comment
Question by:chokka
3 Comments
 
LVL 19

Accepted Solution

by:
simon3270 earned 250 total points
ID: 40325746
Easiest would be

    mv $1 $2

then you call it as

    ./script.sh /home/testuser/file.csv /home/admin/user2/destination/file.csv

(UNIX/Linux use forward slashes between directories, Windows uses backslash)
0
 
LVL 14

Assisted Solution

by:ThomasMcA2
ThomasMcA2 earned 250 total points
ID: 40325777
Also, if your input paths might include spaces, wrap the parms with double quotes, like this:

mv "$1" "$2"
0
 
LVL 23

Expert Comment

by:savone
ID: 40325829
mv would be a move, which would be like a cut and paste as opposed to copy and paste.  

Try this...


echo "Copying $1 to $2"
cp "$1" "$2"
echo "Copy completed"

Open in new window

0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
Viewers will learn how to use the Hootsuite Dashboard.

863 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

20 Experts available now in Live!

Get 1:1 Help Now