error checking = error creating

So, I write bash scripts that think of everything, or as much as it matters to a script. Being clever, I have my backup script check the destination directory actually exists before moving the archive zip over, and if not, creates it. OF COURSE! So it is...

Insert elevator-style music, change of subject material …

And so here I am, YEARS later, wondering why my local Linux server has more than 8GB less free space than I expect. That's a lot of space on an old laptop. For a couple of days I'm in PuTTY every chance I get running fancy du and df commands trying to figure out what's going on.

For the UnLinuxed, network "shares" get mounted into empty directories (aka. "folders). It's a neat system. You simply create an empty dir (the regular ones; cdrom, dvd, SD and so on are created already) , e.g..


… then tell Linux to mount the share into that dir - either with some arcane mount command, or else by dropping a line in your fstab somehow, e.g..

//Station/BackupDrive /mnt/Station/BackupDrive cifs credentials=/root/.smbpasswd,rw,uid=cor,gid=adm 0 0

Voila, dive into the dir and it's your "BackupDrive" network share. Excellent.

But what if, for some reason, that network share couldn't be mounted and then some brain-dead script decides to just create the directory it needs and move files into it. What would happen the next time the share (and the user of that's share's actual computer workstation) re-appeared and mounted the share into the supposed-to-be empty directory?

The previous contents of /mnt/Station/BackupDrive/ vanish, that's what!

df will show you that the space is used, but df will not agree, and will tell you a different story; not that anyone is daft enough to include network shares in their du command (there's a switch for that, see: df --help or man df).

SO, I unmount the shares, 9GB of backups live there. Squatting.

So much for thinking ahead!


ps. I should add that the solution is to chmod those directories 000, so no script can ever write to them, logs an error, instead.

 ©  2024 « » 24.6.22  

Welcome to!

I'm always messing around with the back-end.. See a bug? Wait a minute and try again. Still see a bug? Mail Me!