We help IT Professionals succeed at work.
Get Started

Unix Korn / Bourne Shell script to prompt step by step /simplify scp copying

sunhux asked
Last Modified: 2013-12-26

The computer operators need to do scp from several Unix (HP-UX & Linux) servers
to a dedicated PC on a frequent basis via Tcp2222.

So on those one dozen over Unix servers, I would issue :
  scp -P2222 source_file_on_Unix administrator@localhost:/g/temp
      Or to copy an entire directory,
  scp -P2222 -r source_dir_on_Unix administrator@localhost:/g/temp

where -P2222 is to make scp to copy via Tcp2222 while /g/temp   is the drive &
directory on the PC.  I'll need a Korn/Bourne Shell script (as our servers
don't have bash), call it ncp to prompt operators step by step ie :

In most cases,
- the operators copy files (about 85-95% of the times) rather than entire directory
- the operators use putty (so they can easily select & paste filenames)

So ideally the requirements for the script :

Just type "ncp"  (I'll put this script in the path)

&  it will prompt them :

Question / prompt 1 : 1) Are you copying entire directory/folder? y/n/Y/N (default n or just ENTER
  as most of the times, it's files copying) :
If y, Question /prompt 2: 2) Enter source subdirectory name :
If n (or just <ENTER>), then prompt for following questions:

Question / prompt 3 : 3) Pls input source file1 (hit ENTER if no more source file) :
Question / prompt 4 : 4) Pls input next source file (hit <ENTER>) if there's no more) :
Question / prompt N: N)     ..... (to input the Nth file) .....
Last Question/prompt :   Pls input the destination drive & folder (eg: /c/temp format) :
Echo  "for text files, pls use WordPad or MSWord to open/read them on Windows"

lastly, if the script could input the PC's administrator's password (ie required by scp),
(let's call it  pcpassword), that would be ideal, if not, then let the operators enter the
password manually.

We don't want to use private+public key pairs due as we hv to go thru cumbersome
Change Requests
Watch Question
This problem has been solved!
Unlock 2 Answers and 22 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE