Y
Y
YaroslavKleyno2018-03-09 11:43:29
linux
YaroslavKleyno, 2018-03-09 11:43:29

How to write a script to unmount disks in bash?

Good afternoon! The situation is this - there is a directory / media , flash drives inserted by users are automatically connected to it via pmount. When you connect a flash drive, a directory with the name of the flash drive is created.
It is necessary that when this machine is turned off, the pumount command is executed for each directory
[[email protected] media]# ls /media
Nomi_i184 UBUNTU
From here it is necessary that the following commands be executed when the machine is turned off
pumount --yes-I-really-want-lazy-unmount /media /Nomi_i184
pumount --yes-I-really-want-lazy-unmount /media/Ubuntu
How to implement this in bash?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
Y
YaroslavKleyno, 2018-03-09
@YaroslavKleyno

Decided:

#!/bin/bash
for D in /media/*; do
    if [ -d "${D}" ]; then
        pumount --yes-I-really-want-lazy-unmount "${D}"
    fi
done

D
Dmitry, 2018-03-09
@demon416nds

I don’t use bash,
but logically it should be like this
pumount / media / *

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question