for file in /path/to/file1.txt /path/to/file2.txt /path/to/file3.txt
do
# do something on $file
cat "$file"
done
You can directly process all command line args:
for file in $*
do
# do something on $file
[ -f "$file" ][ "$d" != "" ][ "$f" == "start" ][ "$f" == "end" ] && echo "=============================================================="
}
source /usr/local/nixcraft/mgmt/ssh/.keychain/$HOSTNAME-sh
for d in $domains
do
logdata "start" "$d @ $(date)"
[ -d "/home/wwwdata/$d/" ] && { cd "/home/wwwdata/$d/";
/usr/bin/rsync --exclude='cache/cache-*'\
--exclude '.bash_history' \
--exclude '.viminfo' \
--exclude 'cache/*_mutex.lock' \
--exclude 'broken-link-checker*' \
--exclude 'tmp/*'
-a --delete . backup@nasbox.nixcraft.net.in:/raid6/$HOSTNAME/ ;
}
logdata "end" "$d @ $(date)"
done &> $log
[ -f $latest ] && /bin/rm -f $latest
ln -s $log $latest
mail -s "Backup $HOSTNAME" admin@clients.nixcraft.net.in < $latest
do
# do something on $file
cat "$file"
done
You can directly process all command line args:
for file in $*
do
# do something on $file
[ -f "$file" ][ "$d" != "" ][ "$f" == "start" ][ "$f" == "end" ] && echo "=============================================================="
}
source /usr/local/nixcraft/mgmt/ssh/.keychain/$HOSTNAME-sh
for d in $domains
do
logdata "start" "$d @ $(date)"
[ -d "/home/wwwdata/$d/" ] && { cd "/home/wwwdata/$d/";
/usr/bin/rsync --exclude='cache/cache-*'\
--exclude '.bash_history' \
--exclude '.viminfo' \
--exclude 'cache/*_mutex.lock' \
--exclude 'broken-link-checker*' \
--exclude 'tmp/*'
-a --delete . backup@nasbox.nixcraft.net.in:/raid6/$HOSTNAME/ ;
}
logdata "end" "$d @ $(date)"
done &> $log
[ -f $latest ] && /bin/rm -f $latest
ln -s $log $latest
mail -s "Backup $HOSTNAME" admin@clients.nixcraft.net.in < $latest
#!/bin/bash
export PATH
echo "$PATH"
rename .txt .xml *
for file in *.xml
do
dos2unix "$file"
done
本文介绍了一个用于批量处理文件并实现自动化备份的脚本。通过使用`forfile`命令,脚本能够直接处理命令行参数,针对每个文件执行特定操作,如查看文件内容、复制文件内容到日志、同步文件到远程服务器、删除旧的日志文件,并创建软链接到最新的日志。此外,脚本还包含了定时备份和文件同步的功能。
1051

被折叠的 条评论
为什么被折叠?



