LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-05-2020, 04:45 PM   #1
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Rep: Reputation: 56
Mount/Umount mount point from with a script


Hello All

I'm writing a shell script that will mount/umount LUKS encrypted devices into a directory. I'll add many functions to it later.

For now, I'm stuck on two things:
  1. Mounting: You are in one directory, and you mount a partition on to that same directory. Then you will not see any new files in that directory. You have to move out of that directory and come back to that directory to see files. In script, is there a way to 'kind a refresh' that directory so you see the files?
  2. Unmounting: Same thing. You cannot unmount from that directory when it is your current directory. In shell script, how do I unmount, when I execute the shell script from the same directory?

This is the link for my code in GitHub that I newly created. The shell script is 'myluks.sh'

Right now, I have dealt it with some different way, but I'm not its the right way.

Appriciate any comment/suggestions.

Thanks

Last edited by ddenial; 08-05-2020 at 04:46 PM.
 
Old 08-05-2020, 06:38 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
I don't have the time right now to analyze your script, but this should work (relevant commands are in bold blue font):
Code:
#!/bin/bash
cd /mnt/sdb
echo mounting
mount /dev/sdb /mnt/sdb
echo listing1
ls -F         # displays pre-mount list
echo listing2
cd $PWD
ls -F         # displays correct list
echo unmounting
umount /dev/sdb     # fails
cd /tmp
echo unmounting again 
umount /dev/sdb     # succeeds
cd -
echo listing 3
ls -F

Last edited by berndbausch; 08-05-2020 at 06:39 PM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[7.3] umount says: "umount: /very/long/path (/dev/loop0) is unmounted" ? McZ Linux From Scratch 4 03-24-2013 01:29 PM
How to force umount Fat32 mount point linuxlainen Linux - Newbie 5 08-18-2008 01:38 PM
mount NFS to mount point then share out the mount point ionic_slim Linux - Networking 2 04-20-2008 12:17 PM
Mount. Umount. Mount. Umount. Mount. Umount. Mount.. cwizardone Slackware 10 03-22-2007 09:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration