开发者

Need help with ssh script

I'm very new with ssh so I need some help to write so开发者_StackOverflow中文版me 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


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜