如何自动挂载目录?

Bash

1 前言

一个问题,一篇文章,一出故事。
笔者需要写一个脚本定时挂载目录,但是AutoFS测试过骨兼容,于是整理此文。
如果你对AutoFS有兴趣,请参阅如下章节,否则请跳过,

如何配置nfs客户端挂载?

如何配置samba客户端挂载?

2 最佳实践

2.3 创建文件上传脚本

mkdir -p ~/scripts/
vim ~/scripts/mountminiotool.sh

加入如下脚本,

#!/bin/bash

mountPion="/miniods"
minioBucket="https://minio.cmdschool.org:9000/mybucket"
mountOption="defaults,cache=/tmp/mybucket"
mountType="minfs"
logFile="/var/log/mountminio.log"

if [ ! -d "$mountPion" ]; then
        mkdir -p "$mountPion"
fi

if [ "`mount | grep -i '^MinFS' | cut -d' ' -f3`" == "$mountPion" ]; then
        exit
fi
/usr/bin/mount -t "$mountType" -o "$mountOption" "$minioBucket" "$mountPion"
now=`date +"%Y-%m-%d %H:%M:%S"`
if [ $? = 0 ]; then
        echo "$now"" Mount successfully!" >> "$logFile"
else
        echo "$now"" Mount failed!" >> "$logFile"
fi

2.4 测试脚本

bash ~/scripts/mountminiotool.sh

2.5 设置脚本触发

crontab -e

加入如下触发规则,

*/1 * * * * bash ~/scripts/mountminiotool.sh
没有评论

发表回复

Bash
如何用Tigase监控Elasticsearch集群?

1 前言 一个问题,一篇文章,一出故事。 笔者生产中有一套Elasticsearch集群,笔者为了能 …

Bash
如何用Base Shell获取ES集群状态?

1 前言 一个问题,一篇文章,一出故事。 笔者想要通过Base Shell获取Elasticsear …

Bash
如何熟悉grep命令?

截取括弧“()”中的字符串, echo “This is a test (sample string …