Solved

Linux Shell Script for copy file

Posted on 2014-09-16
3
444 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Today companies are subjected to more-and-more data, and it won't stop any time soon.  But there are obvious opportunities for reducing data, particularly data duplicated among companies.
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The viewer will learn how to set up a document for the web and print and the recommended PPI for printing.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

828 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