我正在编写一个小脚本来组合一些步骤,但最终我得到了:
scp: .: not a regular file
cp: cannot stat ‘/path/to/dir/': No such file or directory
我已经检查过该目录确实存在,它与dir_[0][:-1]
这是代码:
import os
import subprocess
import argparse
parser = argparse.ArgumentParser(prog='get_f.py', description=__doc__)
parser.add_argument('-s', '--sub', help='particpant that you want to get dicoms for')
parser.add_argument('-u', '--user_acc', help='your user name')
parser.add_argument('-dd', '--dicom_dir', help='directory where dicoms are stored')
args = parser.parse_args()
sub = args.sub
user_acc = args.user_acc
dicom_dir = args.dicom_dir
subprocess.call(['ssh', '%s@sew.cwe.edu' % user_acc, '-t', 'sessionfinder',
'--s', '%s' % sub, '>', '%s.txt' % sub, ';', 'sed',
'-i', """'s/ /\\n/g'""", '%s.txt' % sub, ';', 'tail',
'-2', '%s.txt' % sub,'|', 'head', '-1', '>', 'dir.txt', ';'
'rm', '%s.txt' % sub])
if not os.path.isdir('%s//%s' % (dicom_dir, sub)):
subprocess.call(['mkdir', '%s//%s' % (dicom_dir, sub)])
subprocess.call(['ssh', '%s@sew.cwe.edu' % user_acc, '-t', 'scp', 'dir.txt',
'%s@suo.cwe.edu:%s//%s' % (user_acc, dicom_dir, sub), ';',
'rm', 'dir.txt'])
if not os.path.isdir('%s//%s/dicom' % (dicom_dir, sub)):
os.makedirs('%s//%s/dicom' % (dicom_dir, sub))
with open('%s//%s/dir.txt' % (dicom_dir, sub)) as f:
dir_ = f.readlines()
subprocess.call(['scp', '%s@sew.cwe.edu:' % user_acc, dir_[0][:-1],
'%s//%s/dicom/' % (dicom_dir, sub)])
我尝试将-r
和-pr
添加到scp
,但似乎没有任何效果
答案 0 :(得分:1)
您对// Do not do this
$target = $_GET['user'];
mysqli_query($connection,"SELECT username FROM user WHERE id='$target' ")
的调用不是返回字符串,而是返回列表
dir_[0][:-1]
试试这个:
user_acc = 'alan'
dir_ = [['src', 'main'],['opt', 'user']]
dicom_dir = '/var/tmp'
sub = '/subdir'
print ('scp', '%s@sew.cwe.edu:' % user_acc, dir_[0][:-1], '%s//%s/dicom/' % (dicom_dir, sub))
>> scp alan@sew.cwe.edu: ['src'] /var/tmp///subdir/dicom/
print ('scp', '%s@sew.cwe.edu:' % user_acc + ''.join(dir_[0][:-1]), '%s//%s/dicom/' % (dicom_dir, sub))
>> scp alan@sew.cwe.edu:src /var/tmp///subdir/dicom/