rcp not working?

I'm trying to copy a file from a remote unix box, host1, to my unix box, host2. The first line of code gets the last word from a text document (this is the name of the file I need from host1)

#!/usr/bin/ksh
tail -1 Report.txt | perl -e '@arr = split /\//,<>; lastWord = $arr[-1]'
rcp host1:/tmp/$lastWord .

I get the following error:

rcp: /tmp: not a plain file

rcp is trying to copy the whole /tmp directory for some reason. I need just the 1 file.

From the code, you are trying to run the command for "lastWord" on the local machine and then trying to copy the file from the remote machine which is not present there. The file you have generated is on local machine.

Actually, I suspect that it's because the variable declaration is within the perl subshell, and isn't being 'exported' to be used in his rcp function. I'm afraid my perl isn't very good, but to get the last word without it and then actually use that:

rcp host1:/tmp/$(tail -1 Report.txt | sed 's/^.*\ \([^\ ]*$\)/\1/g') .
1 Like

thanks a lot, this worked.