 Hello and welcome today. We're going to be looking at writing a script that waits for a certain device in this particular case We're gonna be waiting for a flash drive. Now all disks all drives on your computer will have a UU ID and identification Usually string of digits. It's something that you can you can manually change when you format it But unless you go and change it for that device It's going to constantly stay the same each time you plug it in so you can look for this and Wait for a device now. This is different than saying your device There are options in there that I've gone over in the past that basically constantly look for certain things to be plugged in This is you're running a script the script will say okay now plug in this device And it will wait for that device before this particular script continues running So real quick if I list out in our dev folder, we're gonna have dev and then disk will be our disk devices We there's another folder in there called by UU ID. This will list them out by UU ID So we run that and you can see I have a couple of devices if I was to give the longer command for ls of dash L It would actually show you what drives they're pointing to but now remember something like this device is SDA1 that may change depending on the order of devices being plugged in where the UU ID should stay the same unless again You change it yourself, which is a process of doing is not just going to happen So right now, let me go back and clear the screen list out all Files or in this case links inside this folder. You can see them all I'm gonna plug in a flash drive wait a second And then I'm going to run this list command again, and you can see there is a new one It's this one right here the o3 cb-1 c0 f Okay So I can take that put it in my script and tell my script to keep checking for this device and wait for it to exist Again, it doesn't need to be mounted right now. It's not mounted. It's just looking to see if it's plugged in And then you can have your script mounted if you want or format it or do whatever you want or just do something Has nothing to do with the drive But I already have the script written. I'm going to put this up on paceman There'll be a link in the description to where you can find it But let's go over it real quick. So very short here I'm setting a variable to the UU ID of that device and then I'm setting where it should look for that Now it's going to say please attach that device and then wait for UU ID, okay? We're going to say dash and that says no new line So what I'm going to do here is just give you some output that the script is still running So now we're going to say okay If this link does not exist keep looping, okay So it's looking for this drive and every second it's going to loop so it's and each time it loops It's going to print out a new period dot dot dot just to give you some indication that the script is still running and waiting And we'll check every second once it loops and finds that it exists It will break out of this loop and then continue in this case We're just going to print a message of it is connected and of course you can do whatever you want in your script after that Let's go ahead quit out of this. We will run this. Well first. Let me unplug the drive and Now I will run the script and you can see that it is waiting and you can see the dot dot dot just a little indication that it's still waiting Please attach this device and I will plug it in and it should only take a second or two There you go device is connected So that's how you do that. You just wait till the device exists. It's loop and again This is different. It's not something you're going to run in the background all the time There's other options for that But for this particular case again, you might have a script that you want to wait for a certain Device to exist before continuing. So I thank you for watching films by chris.com. That's Chris the K There's a link in the description and as always. I hope that you have a great day