Solved

Linux Shell Script for copy file

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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

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…
Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

630 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