【发布时间】:2016-05-14 00:58:49
【问题描述】:
通过 shell 脚本检查文件夹和内部文件是否存在
这是我用来检查文件夹以及其中是否包含文件的脚本。但它不采用文件名。请帮我解决问题。
#!/bin/bash
folder1="/root/scripts/1/"
folder2="/root/scripts/2/"
folder3="/root/scripts/3/"
file1=start.sh
file2=stop.sh
CHKFOLDERS="folder1,folder2,folder3"
CHKFILES="file1,file2"
# Check all passed path & programs are exist or not with needed permission like execute.
for fol in $(echo $CHKFOLDERS | sed "s/,/ /g"); do
if [ ! -d "$fol" ]; then
echo -e " $fol folder are not correct please check."
exit 1
fi
for infile in $(echo $CHKFILES | sed "s/,/ /g"); do
if [ ! -x "$((fol))/${fol}_${infile}" ]; then
echo -e " \"${fol}_${infile}\" script is not correct or not executable please ckeck this."
exit 2
fi
done
done
在本例中,命名约定如下:
文件夹名称:文件夹1、文件夹2、文件夹3
文件名:folder1_file1、folder2_file2。
【问题讨论】: