Solved

Linux Shell Script for copy file

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A list of useful business intelligence software.
Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

705 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

17 Experts available now in Live!

Get 1:1 Help Now