PuppyThis forum is for the discussion of Puppy Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
if [ "`lsblk -o name|grep sdb1`" = "" ]; then echo "no device /dev/sdb1"; fi
If you get no output that doesn't mean that /dev/sdb1 is mounted, but you can mount it if you don't get the message and it's not already mounted. You can check the output of "mount" or of "lsblk -o name,mountpoint|grep sdb1 to see if it's already mounted.
Last edited by Didier Spaier; 05-30-2015 at 08:17 AM.
In addition to the pointer michaelk gave you, try this:
Code:
man bash
But as this man page is huge and as bash is an implementation of the Shell Command Language you could begin with reading the relevant part of the POSIX specification that is easier to understand for beginners in my opinion. Just bear in mind that bash has also a lot of specific features.
PS your test checks that the USB drive is connected and mounted. I assume that's what you actually wanted.
Last edited by Didier Spaier; 05-30-2015 at 10:37 AM.
If this is in a script, you could run the stat command on the mountpoint and verify that the "Device" field is different from that of the root filesystem.
For my own systems, my backup drives have only a subdirectory at their top level, and all backups are directed to that subdirectory, e.g., "/mnt/backups/bkups". If the drive is not mounted, that "bkups" directory won't exist, and the backup fails.
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150
Rep:
try the findmnt command, it is part of util-linux so should be available in most systems, also lsblk is part of the same package and does a similar thing to blkid also findfs
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.