【发布时间】:2020-04-23 12:50:41
【问题描述】:
我编写了一个脚本来使用 inotify 监视特定目录。如果创建了任何新目录。我想用“z.sh”文件中新创建的目录名替换它。但是我在使用下面的脚本时得到了整个路径而不是目录名。
#!/bin/sh
MONITORDIR1="/var/lib/clickhouse/data/"
monitor() {
inotifywait -m -r -q $MONITORDIR1 | while read NEWFILE
do
echo "NEW FOLDER CREATED"
cp /home/boctrainee/clickhousescriptold.sql /home/boctrainee/clickhousescript.sql
echo "${NEWFILE#*/*/*/*/*/}"
sed -i -e "s+NEWFILE#*/*/*/*/*/+$NEWTENANTNAME+g" /home/boctrainee/clickhousescript.sql
done
}
monitor $MONITORDIR1 &
请提出您的建议
【问题讨论】:
标签: linux bash shell scripting