View previous topic :: View next topic |
Author |
Message |
crimson Guru
Joined: 27 Apr 2002 Posts: 430 Location: Cedar Rapids, IA
|
Posted: Fri Apr 04, 2008 6:42 pm Post subject: Samba - ls takes forever on disconnected mounted drives |
|
|
I have samba installed on my Gentoo box, and filesharing on my Windows boxes. It works pretty well, and I have linux mount the Windows shares on system startup.
My only problem is, sometimes a Windows box needs to be restarted, or even crashes (imagine that), and now my Gentoo box doesn't recognize this has happened, and when I do Code: | ls /mnt/samba/computa/c | the ls command just hangs for about 30sec - 1 min. before outputting:
Code: | ls: cannot access computa/c: Input/output error |
During this minute I cannot hit CTRL-C to cancel the command.
The ideal solution would be this:
-auto unmount the shared drive and all of its folder mountpoints when the connection goes down, and automount the drive/folders when it comes back online. Maybe by an /etc/cron.hourly that pings the windows box? I'm not quite sure the best way to do this, but I am sure i could write the cron script. Maybe there's something that will do this already.
But I would settle for just being able to have the ls command give up after say 2 seconds on a network share if it isn't responding.
Suggestions? |
|
Back to top |
|
|
crimson Guru
Joined: 27 Apr 2002 Posts: 430 Location: Cedar Rapids, IA
|
Posted: Fri Apr 04, 2008 8:05 pm Post subject: |
|
|
Well here I am one hour later, I went ahead and wrote a script. It works. I am not a good coder, maybe give me a tip or two, but it does what I want. I am still looking for a better solution, and still looking to find out how to make the ls command not take 30 sec on up to stop hanging.
Heres the script:
Code: |
#!/bin/bash
# smbmountright
# Pings hosts and if they are up and smb mounts are down, mounts shares.
# if they are down and smb mounts are up, umounts shares.
# put in /etc/cron.hourly to keep smb mounts in order.
# 4/4/08
HOSTS='illuminati computa'
SHARE_DIR='/mnt/samba'
for i in $HOSTS; do
pingStatus="$(ping -c3 $i | grep '0 received')"
mountStatus="$(grep $i /etc/mtab)"
if [ -z "$pingStatus" ] #if $pingStatus is empty, then host is up
then
echo "$i is up"
if [ -z "$mountStatus" ] #if $mountStatus is empty, then mounts are down
then
# mount all shares in directory
for j in $(ls $SHARE_DIR/$i); do
echo "mounting $j on $i"
mount $SHARE_DIR/$i/$j
done
fi
else # host is down
echo "$i is down"
if [ -n "$mountStatus" ] #if $mountStatus is non-empty, then mounts are up.
then
# umount all shares in directory
for k in $(ls $SHARE_DIR/$i); do
echo "umounting $k on $i"
umount $SHARE_DIR/$i/$k
done
fi
fi
done
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|