How to detect USB flash drive is unplugged
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
1
down vote
favorite
On a backup process the program has to copy tar.gz
file to a mounted USB flash drive. The program (nodeJS) uses API child_process.exec()
to run the shell script.
The function itself obtains the stdio
.
So, using a shell script, how can I check whether the USBFlashDrive is disconnected/unplugged?
The device usually appears as sd[a-z]1
- please note the regex in the string.
command-line bash usb
 |Â
show 2 more comments
up vote
1
down vote
favorite
On a backup process the program has to copy tar.gz
file to a mounted USB flash drive. The program (nodeJS) uses API child_process.exec()
to run the shell script.
The function itself obtains the stdio
.
So, using a shell script, how can I check whether the USBFlashDrive is disconnected/unplugged?
The device usually appears as sd[a-z]1
- please note the regex in the string.
command-line bash usb
2
What exactly do you want to do? Do you want to check whether the USB drive is plugged in, or mounted, or actually not plugged in? What information do you have about the USB stick â is it just one specific drive? Or do you rather want to test a specific mount point for a drive to be mounted there? Please edit your question and clarify, do not use comments.
â dessert
May 16 at 10:38
1
I would recommend that you find and use the UUID of the partition on the target device (on the USB flash drive). It is unique, and you can use it for a reliable identification, and then check if that partition is mounted, if it is connected and needs mounting, or not available at all (unplugged). -- A weaker alternative is to use the label (but maybe more convenient).
â sudodus
May 16 at 11:30
@sudodus Thank you for the answer. I don't want to find unique USB device. Any flash drive connected to the usb port would be the correct one. So I want to check if any usb device is connected, not certain usb.
â Hairi
May 16 at 13:21
1
What about other USB drives (for example a USB HDD or USB SSD)? I guess you would not want to write to them (or maybe that would be OK too). And there can be more than one partition. How would you tell the difference?
â sudodus
May 16 at 13:25
2
Maybe creating a label on the target partition in each of the USB drives, that you want to use, and mount it according to the label. You can use the same label on all the USB drives, that you want to use for this purpose, and it will work when each of them is connected alone. But if you connect more than one of them at the same time, there might be confusion (you may not know which of the drives that will be the target).
â sudodus
May 16 at 13:33
 |Â
show 2 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
On a backup process the program has to copy tar.gz
file to a mounted USB flash drive. The program (nodeJS) uses API child_process.exec()
to run the shell script.
The function itself obtains the stdio
.
So, using a shell script, how can I check whether the USBFlashDrive is disconnected/unplugged?
The device usually appears as sd[a-z]1
- please note the regex in the string.
command-line bash usb
On a backup process the program has to copy tar.gz
file to a mounted USB flash drive. The program (nodeJS) uses API child_process.exec()
to run the shell script.
The function itself obtains the stdio
.
So, using a shell script, how can I check whether the USBFlashDrive is disconnected/unplugged?
The device usually appears as sd[a-z]1
- please note the regex in the string.
command-line bash usb
edited May 23 at 19:46
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
Zanna
47.9k13117227
47.9k13117227
asked May 16 at 9:32
![](https://i.stack.imgur.com/aUJPQ.jpg?s=32&g=1)
![](https://i.stack.imgur.com/aUJPQ.jpg?s=32&g=1)
Hairi
1062
1062
2
What exactly do you want to do? Do you want to check whether the USB drive is plugged in, or mounted, or actually not plugged in? What information do you have about the USB stick â is it just one specific drive? Or do you rather want to test a specific mount point for a drive to be mounted there? Please edit your question and clarify, do not use comments.
â dessert
May 16 at 10:38
1
I would recommend that you find and use the UUID of the partition on the target device (on the USB flash drive). It is unique, and you can use it for a reliable identification, and then check if that partition is mounted, if it is connected and needs mounting, or not available at all (unplugged). -- A weaker alternative is to use the label (but maybe more convenient).
â sudodus
May 16 at 11:30
@sudodus Thank you for the answer. I don't want to find unique USB device. Any flash drive connected to the usb port would be the correct one. So I want to check if any usb device is connected, not certain usb.
â Hairi
May 16 at 13:21
1
What about other USB drives (for example a USB HDD or USB SSD)? I guess you would not want to write to them (or maybe that would be OK too). And there can be more than one partition. How would you tell the difference?
â sudodus
May 16 at 13:25
2
Maybe creating a label on the target partition in each of the USB drives, that you want to use, and mount it according to the label. You can use the same label on all the USB drives, that you want to use for this purpose, and it will work when each of them is connected alone. But if you connect more than one of them at the same time, there might be confusion (you may not know which of the drives that will be the target).
â sudodus
May 16 at 13:33
 |Â
show 2 more comments
2
What exactly do you want to do? Do you want to check whether the USB drive is plugged in, or mounted, or actually not plugged in? What information do you have about the USB stick â is it just one specific drive? Or do you rather want to test a specific mount point for a drive to be mounted there? Please edit your question and clarify, do not use comments.
â dessert
May 16 at 10:38
1
I would recommend that you find and use the UUID of the partition on the target device (on the USB flash drive). It is unique, and you can use it for a reliable identification, and then check if that partition is mounted, if it is connected and needs mounting, or not available at all (unplugged). -- A weaker alternative is to use the label (but maybe more convenient).
â sudodus
May 16 at 11:30
@sudodus Thank you for the answer. I don't want to find unique USB device. Any flash drive connected to the usb port would be the correct one. So I want to check if any usb device is connected, not certain usb.
â Hairi
May 16 at 13:21
1
What about other USB drives (for example a USB HDD or USB SSD)? I guess you would not want to write to them (or maybe that would be OK too). And there can be more than one partition. How would you tell the difference?
â sudodus
May 16 at 13:25
2
Maybe creating a label on the target partition in each of the USB drives, that you want to use, and mount it according to the label. You can use the same label on all the USB drives, that you want to use for this purpose, and it will work when each of them is connected alone. But if you connect more than one of them at the same time, there might be confusion (you may not know which of the drives that will be the target).
â sudodus
May 16 at 13:33
2
2
What exactly do you want to do? Do you want to check whether the USB drive is plugged in, or mounted, or actually not plugged in? What information do you have about the USB stick â is it just one specific drive? Or do you rather want to test a specific mount point for a drive to be mounted there? Please edit your question and clarify, do not use comments.
â dessert
May 16 at 10:38
What exactly do you want to do? Do you want to check whether the USB drive is plugged in, or mounted, or actually not plugged in? What information do you have about the USB stick â is it just one specific drive? Or do you rather want to test a specific mount point for a drive to be mounted there? Please edit your question and clarify, do not use comments.
â dessert
May 16 at 10:38
1
1
I would recommend that you find and use the UUID of the partition on the target device (on the USB flash drive). It is unique, and you can use it for a reliable identification, and then check if that partition is mounted, if it is connected and needs mounting, or not available at all (unplugged). -- A weaker alternative is to use the label (but maybe more convenient).
â sudodus
May 16 at 11:30
I would recommend that you find and use the UUID of the partition on the target device (on the USB flash drive). It is unique, and you can use it for a reliable identification, and then check if that partition is mounted, if it is connected and needs mounting, or not available at all (unplugged). -- A weaker alternative is to use the label (but maybe more convenient).
â sudodus
May 16 at 11:30
@sudodus Thank you for the answer. I don't want to find unique USB device. Any flash drive connected to the usb port would be the correct one. So I want to check if any usb device is connected, not certain usb.
â Hairi
May 16 at 13:21
@sudodus Thank you for the answer. I don't want to find unique USB device. Any flash drive connected to the usb port would be the correct one. So I want to check if any usb device is connected, not certain usb.
â Hairi
May 16 at 13:21
1
1
What about other USB drives (for example a USB HDD or USB SSD)? I guess you would not want to write to them (or maybe that would be OK too). And there can be more than one partition. How would you tell the difference?
â sudodus
May 16 at 13:25
What about other USB drives (for example a USB HDD or USB SSD)? I guess you would not want to write to them (or maybe that would be OK too). And there can be more than one partition. How would you tell the difference?
â sudodus
May 16 at 13:25
2
2
Maybe creating a label on the target partition in each of the USB drives, that you want to use, and mount it according to the label. You can use the same label on all the USB drives, that you want to use for this purpose, and it will work when each of them is connected alone. But if you connect more than one of them at the same time, there might be confusion (you may not know which of the drives that will be the target).
â sudodus
May 16 at 13:33
Maybe creating a label on the target partition in each of the USB drives, that you want to use, and mount it according to the label. You can use the same label on all the USB drives, that you want to use for this purpose, and it will work when each of them is connected alone. But if you connect more than one of them at the same time, there might be confusion (you may not know which of the drives that will be the target).
â sudodus
May 16 at 13:33
 |Â
show 2 more comments
3 Answers
3
active
oldest
votes
up vote
0
down vote
I suggest
lsusb
according to its author,
lsusb
is a utility for displaying information about USB buses in the system and the devices connected to them.
An example:
hani@My-FRIEND:~$ lsusb
Bus 001 Device 002: ID 8087:8001 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 005: ID 8087:07dc Intel Corp.
Bus 002 Device 004: ID 04f2:b3a3 Chicony Electronics Co., Ltd
Bus 002 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 002 Device 007: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
Bus 002 Device 002: ID 0458:0185 KYE Systems Corp. (Mouse Systems)
Bus 002 Device 006: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
So as you see, the seventh line of the output shows details about the flash drive (USB drive) that is plugged in right now to the computer (via the USB port).
add a comment |Â
up vote
0
down vote
To check which USB disks are connected look in /dev/disk/by-path/
ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF' | sort
The output of previous command will list only usb disks.
grep -v "part"
- excludes the partitions.
sdb
sdc
Then lsblk
command can print some useful info like model and size.
#!/bin/bash
for usb in $(ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF')
do
lsblk -n -d -o NAME,MODEL,VENDOR,SIZE,RM /dev/$usb
done
To check where the partitions of USB disks are mounted
#!/bin/bash
for usbp in $(ls -l /dev/disk/by-path/usb | grep "part" | awk 'print $NF'| awk -F "/" 'print $NF')
do
findmnt -rno TARGET /dev/$usbp
done
add a comment |Â
up vote
0
down vote
I don't know much about nodeJS (I am a C++ guy) but you can check the presence of drive in /dev/
folder.
When I plugged in my pen drive, I get file /dev/sdc
. If I unplugged it then /dev/sdc
vanishes .
Here is some more info about How to check if a file exists in a shell script
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I suggest
lsusb
according to its author,
lsusb
is a utility for displaying information about USB buses in the system and the devices connected to them.
An example:
hani@My-FRIEND:~$ lsusb
Bus 001 Device 002: ID 8087:8001 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 005: ID 8087:07dc Intel Corp.
Bus 002 Device 004: ID 04f2:b3a3 Chicony Electronics Co., Ltd
Bus 002 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 002 Device 007: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
Bus 002 Device 002: ID 0458:0185 KYE Systems Corp. (Mouse Systems)
Bus 002 Device 006: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
So as you see, the seventh line of the output shows details about the flash drive (USB drive) that is plugged in right now to the computer (via the USB port).
add a comment |Â
up vote
0
down vote
I suggest
lsusb
according to its author,
lsusb
is a utility for displaying information about USB buses in the system and the devices connected to them.
An example:
hani@My-FRIEND:~$ lsusb
Bus 001 Device 002: ID 8087:8001 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 005: ID 8087:07dc Intel Corp.
Bus 002 Device 004: ID 04f2:b3a3 Chicony Electronics Co., Ltd
Bus 002 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 002 Device 007: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
Bus 002 Device 002: ID 0458:0185 KYE Systems Corp. (Mouse Systems)
Bus 002 Device 006: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
So as you see, the seventh line of the output shows details about the flash drive (USB drive) that is plugged in right now to the computer (via the USB port).
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I suggest
lsusb
according to its author,
lsusb
is a utility for displaying information about USB buses in the system and the devices connected to them.
An example:
hani@My-FRIEND:~$ lsusb
Bus 001 Device 002: ID 8087:8001 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 005: ID 8087:07dc Intel Corp.
Bus 002 Device 004: ID 04f2:b3a3 Chicony Electronics Co., Ltd
Bus 002 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 002 Device 007: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
Bus 002 Device 002: ID 0458:0185 KYE Systems Corp. (Mouse Systems)
Bus 002 Device 006: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
So as you see, the seventh line of the output shows details about the flash drive (USB drive) that is plugged in right now to the computer (via the USB port).
I suggest
lsusb
according to its author,
lsusb
is a utility for displaying information about USB buses in the system and the devices connected to them.
An example:
hani@My-FRIEND:~$ lsusb
Bus 001 Device 002: ID 8087:8001 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 005: ID 8087:07dc Intel Corp.
Bus 002 Device 004: ID 04f2:b3a3 Chicony Electronics Co., Ltd
Bus 002 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 002 Device 007: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
Bus 002 Device 002: ID 0458:0185 KYE Systems Corp. (Mouse Systems)
Bus 002 Device 006: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
So as you see, the seventh line of the output shows details about the flash drive (USB drive) that is plugged in right now to the computer (via the USB port).
edited May 23 at 19:47
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
Zanna
47.9k13117227
47.9k13117227
answered May 17 at 7:15
singrium
614113
614113
add a comment |Â
add a comment |Â
up vote
0
down vote
To check which USB disks are connected look in /dev/disk/by-path/
ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF' | sort
The output of previous command will list only usb disks.
grep -v "part"
- excludes the partitions.
sdb
sdc
Then lsblk
command can print some useful info like model and size.
#!/bin/bash
for usb in $(ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF')
do
lsblk -n -d -o NAME,MODEL,VENDOR,SIZE,RM /dev/$usb
done
To check where the partitions of USB disks are mounted
#!/bin/bash
for usbp in $(ls -l /dev/disk/by-path/usb | grep "part" | awk 'print $NF'| awk -F "/" 'print $NF')
do
findmnt -rno TARGET /dev/$usbp
done
add a comment |Â
up vote
0
down vote
To check which USB disks are connected look in /dev/disk/by-path/
ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF' | sort
The output of previous command will list only usb disks.
grep -v "part"
- excludes the partitions.
sdb
sdc
Then lsblk
command can print some useful info like model and size.
#!/bin/bash
for usb in $(ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF')
do
lsblk -n -d -o NAME,MODEL,VENDOR,SIZE,RM /dev/$usb
done
To check where the partitions of USB disks are mounted
#!/bin/bash
for usbp in $(ls -l /dev/disk/by-path/usb | grep "part" | awk 'print $NF'| awk -F "/" 'print $NF')
do
findmnt -rno TARGET /dev/$usbp
done
add a comment |Â
up vote
0
down vote
up vote
0
down vote
To check which USB disks are connected look in /dev/disk/by-path/
ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF' | sort
The output of previous command will list only usb disks.
grep -v "part"
- excludes the partitions.
sdb
sdc
Then lsblk
command can print some useful info like model and size.
#!/bin/bash
for usb in $(ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF')
do
lsblk -n -d -o NAME,MODEL,VENDOR,SIZE,RM /dev/$usb
done
To check where the partitions of USB disks are mounted
#!/bin/bash
for usbp in $(ls -l /dev/disk/by-path/usb | grep "part" | awk 'print $NF'| awk -F "/" 'print $NF')
do
findmnt -rno TARGET /dev/$usbp
done
To check which USB disks are connected look in /dev/disk/by-path/
ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF' | sort
The output of previous command will list only usb disks.
grep -v "part"
- excludes the partitions.
sdb
sdc
Then lsblk
command can print some useful info like model and size.
#!/bin/bash
for usb in $(ls -l /dev/disk/by-path/*usb* | grep -v "part" | awk 'print $NF'| awk -F "/" 'print $NF')
do
lsblk -n -d -o NAME,MODEL,VENDOR,SIZE,RM /dev/$usb
done
To check where the partitions of USB disks are mounted
#!/bin/bash
for usbp in $(ls -l /dev/disk/by-path/usb | grep "part" | awk 'print $NF'| awk -F "/" 'print $NF')
do
findmnt -rno TARGET /dev/$usbp
done
edited May 23 at 19:48
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
Zanna
47.9k13117227
47.9k13117227
answered May 17 at 7:01
user829010
add a comment |Â
add a comment |Â
up vote
0
down vote
I don't know much about nodeJS (I am a C++ guy) but you can check the presence of drive in /dev/
folder.
When I plugged in my pen drive, I get file /dev/sdc
. If I unplugged it then /dev/sdc
vanishes .
Here is some more info about How to check if a file exists in a shell script
add a comment |Â
up vote
0
down vote
I don't know much about nodeJS (I am a C++ guy) but you can check the presence of drive in /dev/
folder.
When I plugged in my pen drive, I get file /dev/sdc
. If I unplugged it then /dev/sdc
vanishes .
Here is some more info about How to check if a file exists in a shell script
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I don't know much about nodeJS (I am a C++ guy) but you can check the presence of drive in /dev/
folder.
When I plugged in my pen drive, I get file /dev/sdc
. If I unplugged it then /dev/sdc
vanishes .
Here is some more info about How to check if a file exists in a shell script
I don't know much about nodeJS (I am a C++ guy) but you can check the presence of drive in /dev/
folder.
When I plugged in my pen drive, I get file /dev/sdc
. If I unplugged it then /dev/sdc
vanishes .
Here is some more info about How to check if a file exists in a shell script
edited May 23 at 19:50
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
![](https://i.stack.imgur.com/8CW8e.png?s=32&g=1)
Zanna
47.9k13117227
47.9k13117227
answered May 16 at 9:56
![](https://i.stack.imgur.com/NdcRa.png?s=32&g=1)
![](https://i.stack.imgur.com/NdcRa.png?s=32&g=1)
noone
844420
844420
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1036866%2fhow-to-detect-usb-flash-drive-is-unplugged%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
What exactly do you want to do? Do you want to check whether the USB drive is plugged in, or mounted, or actually not plugged in? What information do you have about the USB stick â is it just one specific drive? Or do you rather want to test a specific mount point for a drive to be mounted there? Please edit your question and clarify, do not use comments.
â dessert
May 16 at 10:38
1
I would recommend that you find and use the UUID of the partition on the target device (on the USB flash drive). It is unique, and you can use it for a reliable identification, and then check if that partition is mounted, if it is connected and needs mounting, or not available at all (unplugged). -- A weaker alternative is to use the label (but maybe more convenient).
â sudodus
May 16 at 11:30
@sudodus Thank you for the answer. I don't want to find unique USB device. Any flash drive connected to the usb port would be the correct one. So I want to check if any usb device is connected, not certain usb.
â Hairi
May 16 at 13:21
1
What about other USB drives (for example a USB HDD or USB SSD)? I guess you would not want to write to them (or maybe that would be OK too). And there can be more than one partition. How would you tell the difference?
â sudodus
May 16 at 13:25
2
Maybe creating a label on the target partition in each of the USB drives, that you want to use, and mount it according to the label. You can use the same label on all the USB drives, that you want to use for this purpose, and it will work when each of them is connected alone. But if you connect more than one of them at the same time, there might be confusion (you may not know which of the drives that will be the target).
â sudodus
May 16 at 13:33