Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fcp command help

Status
Not open for further replies.

mdraja

Programmer
Oct 14, 2003
44
GB
Hi

I am trying to prompt the user to enter a filename after calling the script below and then copy this file to another server. My script works if the user enters the full path of the file (eg)user types:

test.sh /home/script/a.sh

In this situation, tesh.sh will be transferred to /home/script of server2

How can I transfer the file to the same location if the user only types the filename and not the path? In other words, user types:

test.sh a.sh


-------------------------
Contents of test.sh:

#!/bin/sh
USAGE="usage : $0 arg1"

if (($# > 1))
then
print "Error: This script can only copy one file at a time, please enter only one file name"
elif
(($# == 1))
then

rcp $1 server2:$1

-----------------

Thanks for any feedback
 
sorry should read

In this situation, a.sh will be transferred to /home/script of server2


and not
In this situation, tesh.sh will be transferred to /home/script of server2

 
You can try something like this:
Code:
then
 [ -f /home/script/$1 ] && f=/home/script/$1 || f=$1
 rcp $f server2:$f

Hope This Help
PH.
 
Hi PHV

Thanks for the response. However, I may not have made my question too clear. Indeed, I want the script to find out the pwd of the file to copy and transfer this to the same location on the other server.

Therefore, if a.sh was in /home/bin or /home/script, then the script would identify the location and copy this. Hard coding the path wouldn't work in case the file to be copied was in another directory.

Sorry about this, any further ideas?
 
Try this (sh only, not ksh):
Code:
f=`type $1 | sed -e 's!.* !!'`
[ -f $f ] && rcp $f server2:$f || echo "Error with $f"
The script directory must be in the PATH variable.

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top