来自于旧站的重置文章。
前言
今天,拉姐和我说,问有没有什么能够方便scp的方法,不要再一行一行的输入了,一开始和我说要把cluster的盘符挂在到自己的MacBook上,我想了一下可能可以,可能不可以,感觉很高级的样子。
后来想了想,其实还有一个很简单而且扩展性也很高的办法,那就是shell脚本。于是乎就有了这篇博文,这其实我思考了半天应该加入到无敌小白版,还是记录版里面,因为这个实在是一个小问题,于是我打算把他加入到普通的计算机科学里面,唉嘿嘿。
正文
1. Shell读取配置文件
读取配置文件的方法参考《Shell 读取配置文件的方法》的sed流处理器。
然后其实很简单了,读配置文件+scp命令
source=`sed '/^source_path=/!d;s/.*=//' scp.conf`
target=`sed '/^target_path=/!d;s/.*=//' scp.conf`
echo File [$source] is coped to [$target] ...
scp $source $target
2. 编写配置文件
也没什么好写的其实,如下:
source_path=root@8.219.235.26:/root/test
target_path=/Users/seanzou/Downloads/sh4scp/test
3. 给.sh文件权限
输入sudo chmod 777 [filename].sh
,权限用2禁止表示,777表示所有权限,给予rwx给user、group和anyone,关于chmod权限可以看如下,复习一下:
The next nine characters represent the settings for the three sets of permissions.
The first three characters show the permissions for the user who owns the file (user permissions).
The middle three characters show the permissions for members of the file’s group (group permissions).
The last three characters show the permissions for anyone not in the first two categories (other permissions).
The letters represent (three-group):
r: Read permissions. The file can be opened, and its content viewed.
w: Write permissions. The file can be edited, modified, and deleted.
x: Execute permissions. If the file is a script or a program, it can be run (executed).
4. 完成
然后你会有两个文件,一个说来自Section 2的sh4scp.sh和来自Section 3的scp.config,然后只要运行sh4scp.sh就可以了,./sh4scp.sh
,记得./
完成~
总结
学多了一个技能,嘿嘿!以后可以学学如何写Shell!
参考
[1] Shell 读取配置文件的方法
[2] How to Use the chmod Command on Linux