我想知道如何最好地改进mktemp,以便与加密的容器或文件系统一起使用。
我正在处理的问题是,如果可能的话,我希望shell脚本能够在包含工作目录的文件系统中存储临时文件。
mktemp的正常行为似乎是使用环境变量或/tmp中指定的根路径。但是,如果我处理加密容器中的文件,这将定期将临时数据泄漏到未加密的位置。
其思想是首先检查当前文件系统挂载点中是否存在tmp目录,并将/tmp作为最后手段使用。我怎样才能可靠地(有效地)认识到这一点。
<#>编辑
标识给定路径的挂载目录的一种可能方法是:
dir=`realpath [path]`;
res=1;
while [ $res -ne 0 ]; do
dir="${dir%/*}";
mountpoint -q "$dir/";
res=$?;
done;
echo "$dir";不过,我不知道这是否最有效的办法。
发布于 2018-01-05 21:53:36
可以将任何目录指定为mktemp;可以使用-p选项或设置不同的TMPDIR。
-p temp-dir, --tmpdir=temp-dir
temp directory for the file. This option is a member of the
tmpdir class of options.
If this option is not provided, mktemp will use the environment
variable TMPDIR to find a suitable directory. If these are not
available, it will fall back to ~/tmp or /tmp. A
command line argument containing a directory component will con-
flict with this option.例如:
#!/bin/bash
TMPDIR=`pwd`
mktemp发布于 2019-04-11 04:36:19
如果我没有误解您的要求,您需要mktemp /WORKING/DIR/tmp.XXXXXXXXXX,或者您想要的名称是类似的(每个X都被随机字母数字字符替换)。
https://unix.stackexchange.com/questions/415098
复制相似问题