相关疑难解决方法(0)

如何在Bash中解析命令行参数?

说,我有一个用这行调用的脚本:

./myscript -vfd ./foo/bar/someFile -o /fizz/someOtherFile
Run Code Online (Sandbox Code Playgroud)

或者这个:

./myscript -v -f -d -o /fizz/someOtherFile ./foo/bar/someFile 
Run Code Online (Sandbox Code Playgroud)

什么是分析这使得在每一种情况下(或两者的组合)的接受的方式$v,$f以及 $d将全部设置为true$outFile将等于/fizz/someOtherFile

bash scripting command-line arguments getopts

1764
推荐指数
24
解决办法
136万
查看次数

Python Paramiko 目录遍历 SFTP

如何做os.walk(),而是通过SSH在另一台计算机上?问题是它os.walk()在本地机器上执行,我想通过 ssh 连接到另一台名为“sunbeam”的计算机,遍历一个目录并为其中的每个文件生成 MD5 哈希值。

到目前为止我写的看起来像这样(下面的代码),但它不起作用。任何帮助将不胜感激。

try:
    hash_array = []
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect('sunbeam', port=22, username='xxxx', password='filmlight')

    spinner.start()
    for root, dirs, files in os.walk(_path):
        for file in files:
            file_path = os.path.join(os.path.abspath(root), file)

            #  generate hash code for file
            hash_array.append(genMD5hash(file_path))

            file_nb += 1
    spinner.stop()
    spinner.ok('Finished.')

    return hash_array
except Exception as e:
    print(e)
    return None
finally:
    ssh.close() 
Run Code Online (Sandbox Code Playgroud)

python ssh sftp paramiko

5
推荐指数
1
解决办法
2091
查看次数

标签 统计

arguments ×1

bash ×1

command-line ×1

getopts ×1

paramiko ×1

python ×1

scripting ×1

sftp ×1

ssh ×1