joe*_*ert 2 unix filesystems cron
我有两个目录。
/application/inbox
/application/unresponsive
Run Code Online (Sandbox Code Playgroud)
该应用程序在收件箱中查找 *.txt 文件并使用它们。应用程序会定期将这些文件中的条目保存到无响应文件夹中以日期命名 (2009-07-31) 的文件中。
我想设置一个每天运行一次的 cron 作业,将最旧的文件从无响应的邮箱移动到收件箱,添加一个 *.txt 扩展名,以便应用程序接收它。
未经测试,可能有问题:
#!/bin/sh
# last file in list sorted newest->oldest
OLDEST=$(ls -t /application/unresponsive | tail -1)
# make sure $OLDEST isn't empty string
if [ -n $OLDEST ]; then
# quote in case of spaces and remove directory name
mv "$OLDEST" /application/inbox/$(basename "$OLDEST").txt
fi
Run Code Online (Sandbox Code Playgroud)