我使用这个bash-code将文件上传到远程服务器,对于普通文件这很好用:
for i in `find devel/ -newer $UPLOAD_FILE`
do
echo "Upload:" $i
if [ -d $i ]
then
echo "Creating directory" $i
ssh $USER@$SERVER "cd ${REMOTE_PATH}; mkdir -p $i"
continue
fi
if scp -Cp $i $USER@$SERVER:$REMOTE_PATH/$i
then
echo "$i OK"
else
echo "$i NOK"
rm ${UPLOAD_FILE}_tmp
fi
done
Run Code Online (Sandbox Code Playgroud)
唯一的问题是,对于名称中有空格的文件,for循环失败,所以我替换了第一行,如下所示:
find devel/ -newer $UPLOAD_FILE | while read i
do
echo "Upload:" $i
if [ -d $i ]
then
echo "Creating directory" $i
ssh $USER@$SERVER "cd ${REMOTE_PATH}; mkdir -p $i"
continue
fi …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个 shell 脚本,该脚本逐行读取文件并执行命令,其参数取自每行的空格分隔字段。
更准确地说,我需要使用 wget 从第二列中给出的 URL 下载一个文件到第一列中给出的路径。但我不知道如何加载此文件并获取脚本中的值。
文件.txt
file-18.log https://example.com/temp/file-1.log
file-19.log https://example.com/temp/file-2.log
file-20.log https://example.com/temp/file-3.log
file-21.log https://example.com/temp/file-4.log
file-22.log https://example.com/temp/file-5.log
file-23.pdf https://example.com/temp/file-6.pdf
Run Code Online (Sandbox Code Playgroud)
期望的输出是
wget url[1] -o url[0]
wget https://example.com/temp/file-1.log -o file-18.log
wget https://example.com/temp/file-2.log -o file-19.log
...
...
wget https://example.com/temp/file-6.pdf -o file-23.pdf
Run Code Online (Sandbox Code Playgroud)