mkr*_*use 4 bash filenames rename variable-substitution
#!/bin/bash
while read server <&3; do #read server names into the while loop
if [[ ! $server =~ [^[:space:]] ]] ; then #empty line exception
continue
fi
echo "Connecting to - $server"
#ssh "$server" #SSH login
while read updatedfile <&3 && read oldfile <&4; do
echo Comparing $updatedfile with $oldfile
if diff "$updatedfile" "$oldfile" >/dev/null ; then
echo The files compared are the same. No changes were made.
else
echo The files compared are different.
# copy the new file and put it in the right location
# make a back up of the old file and put in right location (time stamp)
# rm the old file (not the back up)
#cp -f -v $newfile
mv $oldfile /home/u0146121/backupfiles/$oldfile_$(date +%F-%T)
fi
done 3</home/u0146121/test/newfiles.txt 4</home/u0146121/test/oldfiles.txt
done 3</home/u0146121/test/servers.txt
Run Code Online (Sandbox Code Playgroud)
这是我的整个剧本
mv $oldfile /home/u0146121/backupfiles/$_$(date +%F)
Run Code Online (Sandbox Code Playgroud)
这会正确移动文件,但会删除实际文件名并仅添加日期。我想保留原始文件名并将当前日期添加到文件名中。
试试mv $oldfile $dest_dir/$oldfile_$(date +%F-%T)。
mv $oldfile /home/u0146121/backupfiles/$_$(date +%F)如果您手动替换$oldfile为文件名,则在单行中工作,但如果您专门引用变量$oldname,$则将跳过$oldfile作为参数并返回历史记录以获取最后一个参数。