在 shell 脚本的 for 循环中需要帮助
Need help in for loop in shell script
我是 shell 脚本的新手。我有一个包含文件名的文件。我想使用该文件名将 rsync 同步到目的地。我用于但不工作。下面是脚本:
basedir=/appshare/customerdata/
backupdir=/backup/
rsync=/usr/bin/rsync
ls -ltrh $basedir | awk {'print '} | grep .[0-9] > /tmp/include.txt
for line in /tmp/include.txt
do
rsync -auvH $basedir$line --exclude-from /tmp/exclude.txt $backupdir
done
此脚本在 运行 时出现以下错误:-
[root@practice Script]# ./customerdata
sending incremental file list
rsync: change_dir "/appshare/customerdata//tmp" failed: No such file or directory (2)
sent 12 bytes received 12 bytes 48.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1052) [sender=3.0.9]
行:
for line in /tmp/include.txt
应该是:
for line in `cat /tmp/include.txt`
此外,不要解析 ls
输出,您可以使用来自 shell:
的通配符
for line in $basedir/?[0-9]*;
do
rsync -auvH $basedir$line --exclude-from /tmp/exclude.txt $backupdir
done
我是 shell 脚本的新手。我有一个包含文件名的文件。我想使用该文件名将 rsync 同步到目的地。我用于但不工作。下面是脚本:
basedir=/appshare/customerdata/
backupdir=/backup/
rsync=/usr/bin/rsync
ls -ltrh $basedir | awk {'print '} | grep .[0-9] > /tmp/include.txt
for line in /tmp/include.txt
do
rsync -auvH $basedir$line --exclude-from /tmp/exclude.txt $backupdir
done
此脚本在 运行 时出现以下错误:-
[root@practice Script]# ./customerdata
sending incremental file list
rsync: change_dir "/appshare/customerdata//tmp" failed: No such file or directory (2)
sent 12 bytes received 12 bytes 48.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1052) [sender=3.0.9]
行:
for line in /tmp/include.txt
应该是:
for line in `cat /tmp/include.txt`
此外,不要解析 ls
输出,您可以使用来自 shell:
for line in $basedir/?[0-9]*;
do
rsync -auvH $basedir$line --exclude-from /tmp/exclude.txt $backupdir
done