views:

23

answers:

2

Hi all, I'm very new with ssh so I need some help to write some scripts. The idea is I have files distributed in different folders on a remote server. I want to copy some certain folders into another new folder also on the same server. Suppose, I know all the name of folders that I want to copy and I can list them in a text file. How can write a script that will automatically transfer all those folders into the place I need?

Also, suppose there is one file in each folder that is encrypted with an individual password. All passwords are known by me. How can I write a script to automatically decrypt them?

If you don't have a directly answer, can you give me a link to a tutorial on writing ssh scripts?

Many thanks

+1  A: 

I think you might be a little confused.

SSH is the tool you use to get to the remote server.

Once you're connected to that remote server, the prompt you see and command line interface is called "sh" or "bash", typically, and is a shell.

What you're looking for is a shell scripting tutorial. You can google for others, but that one looks reasonable.

The simplest thing to do would be to just turn your list of files into a script. It might look something like this:

#!/bin/sh
for file in a, b, c, d; do
    cp $file firstFolderName
done
for file in e, f, g, h; do
    cp -v $file secondFolderName
done
decrypt secondFolderName/c "myPassword"

Obviously, the command to decrypt would depend on what encryption tool you used.

You could save this into a file called myscript.sh and execute it with sh myscript.sh from the command line. You might need to learn about nano, vi, or emacs, or another editor in order to actually edit this script from an ssh terminal session too.

easel
+1, took the words right out of my mouth!
Jim Lewis
A: 

Assuming that by SSH you mean bash accessed through SSH.

Assuming list of files is just like this:

/path/tofile1
/path/to/file/2

You can do:

$ cp `cat listOfInputFiles | xargs` destinationDirectory
Novikov
Great, thank you guys so much for explaining. Special thank to Easel for the explanation of shell. Yes, I was confused with the term.
chepukha