[SOLVED] I want check every minute with ping to u/mount folders on my system
SlackwareThis Forum is for the discussion of Slackware 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.
I want check every minute with ping to u/mount folders on my system
Hi there
* i want make a « Daemon » to check every minute with « ping » command if the variables return 0 or 1
If 0 umount mount points
If 1 check if is already mounted and do nothing, if not mount then mount.
By the moment
Code:
#Monturas CIFS :
# Para permitir eliminar archivos necesitas especificar file_mode=0777,dir_mode=0777,gid=1000,uid=1000 , el (g,u)id=1000 es del usuario guest #Porteus
Geremia=$(ping -c 1 192.168.1.10 | sed -n '5p' | cut -c 24-33)
Edna=$(ping -c 1 192.168.1.11 | sed -n '5p' | cut -c 24-33)
# Parece que tendre que darle permisos usando "sudo" desde el archivo "/etc/sudoers" para des/montar
# Especificamente esas rutas.
if [ "$Geremia" == "0 received" ]; then
sudo umount /cifs/Geremia/Inukaze
sudo umount /cifs/Geremia/Inukaze-en-Familia
sudo umount /cifs/Geremia/Temporal
sudo umount /cifs/Geremia/Josmar
fi
if [ "$Geremia" == "1 received" ]; then
#Primero crear carpetas para los puntos de montaje
mkdir -p "/cifs/Geremia/Temporal"
mkdir -p "/cifs/Geremia/Inukaze"
mkdir -p "/cifs/Geremia/Inukaze-en-Familia"
mkdir -p "/cifs/Geremia/Josmar"
$(sudo mount -t cifs //192.168.1.10/Inukaze /cifs/Geremia/Inukaze -o vers=1.0,username=user,password=user,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL) &
$(sudo mount -t cifs //192.168.1.10/Inukaze-en-Familia /cifs/Geremia/Inukaze-en-Familia -o vers=1.0,username=user,password=user,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL) &
$(sudo mount -t cifs //192.168.1.10/Temporal /cifs/Geremia/Temporal -o vers=1.0,username=user,password=user,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL) &
$(sudo mount -t cifs //192.168.1.10/Josmar /cifs/Geremia/Josmar -o vers=1.0,username=user,password=user,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL) &
fi
if [ "$Edna" == "0 received" ]; then
sudo umount /cifs/Edna/SSD-Gaby
fi
if [ "$Edna" == "1 received" ]; then
#Primero crear carpetas para los puntos de montaje
#sudo mkdir -p "/cifs/Edna/SSD-Gaby"
$(sudo mount -t cifs //192.168.1.11/SSD-Gaby /cifs/Edna/SSD-Gaby -o username=user,password=user,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL) &
fi
* How put this on rc.local, because i try to use :
watch -n 60 Geremia=$(ping -c 1 192.168.1.10 | sed -n '5p' | cut -c 24-33) &
watch -n 61 Edna=$(ping -c 1 192.168.1.11 | sed -n '5p' | cut -c 24-33) &
The second command finish the first "watch" command. but i need check that
i try with crontab -e , but is doing nothing.
but the mount and umount command just can be use by root user, and does not matter is on sudoers file mkdir -p /cifs/<some> every time ask for password.
You can use the daemon supervisor (included since Slackware 15.0) to run in background any program (including here even a Bash script) with the necessary support to run as a system service - i.e. a /etc/rc.d/rc.pingtomount appropriately made in Bash script, which runs/controls a daemon instance which execute your script in background.
If the server becomes unresponsive or offline the unmount command might hang or stall which could force you to kill the unmount command. You might need to force a lazy umount i.e.
umount -f -l /cifs/Geremia/...
Your actually not checking to see if the shares are already mounted just mounting again which is a bit of a waste of time since your checking every minute. Use the mountpoint command to see if the share is mounted.
Does the samba server go offline constantly? Is this a laptop and you want to automatically connect when your on your home LAN? Using autofs might be a better choice since it will only mount when you access the share directory and automatically disconnect after at set idle time.
If the server becomes unresponsive or offline the unmount command might hang or stall which could force you to kill the unmount command. You might need to force a lazy umount i.e.
umount -f -l /cifs/Geremia/...
Yes, those flags -f and -l pinpoint the problem with unmounting after a server has gone down. I am not very familiar with smb/cifs mounts in Linux. I avoid them whenever possible as they lack basic posix functionality we usually take for granted in Unix/Linux. For that reason I usually prefer NFS.
But the two problems addressed with -f and -l are that fact that it it a lot easier to unmount a network drive when the server is still responding and it will be hard unmounting a drive which is being in use by some process.
Every now and then I write here about rc.autofs which enables the automounter. The automounter does not solv the problem with a server unexpectedly going down, but at least it makes sure that network drives are only mounted when needed.
probably automounter would work better (see autofs). It will mount it only if needed and umount if the share is not used for a while.
Yes, nfs would be a better choice (instead of cifs).
By the way, there is a problem with the original approach. If ping fails the remote host is already down and probably you cannot successfully umount that share.
probably automounter would work better (see autofs). It will mount it only if needed and umount if the share is not used for a while.
Yes, nfs would be a better choice (instead of cifs).
By the way, there is a problem with the original approach. If ping fails the remote host is already down and probably you cannot successfully umount that share.
What the heck is
Code:
$(sudo mount -t cifs .....) &
???
nfs is very unstable, i try for six month and nfs just works for 2,4,6,8,10 minutes and after nothing response, cifs works better on domestic lan, ever works.
I have not experienced a NFS stability problem. It appears like you have a LAN problem either wireless or wired and trying to patch it with the script or autofs is not necessarily going to fix the problem.
I have not experienced a NFS stability problem. It appears like you have a LAN problem either wireless or wired and trying to patch it with the script or autofs is not necessarily going to fix the problem.
yes, I think so. But in that case nothing can help. I mean if the connection is unreliable you cannot use it that way, the mount will die sooner or later. Better to use a tool like rsync in such cases.
But return back to the original post: you can configure mount to be able to use it as user, not only as root.
The syntax $(sudo mount .... ) & is wrong.
If the server becomes unresponsive or offline the unmount command might hang or stall which could force you to kill the unmount command. You might need to force a lazy umount i.e.
umount -f -l /cifs/Geremia/...
Your actually not checking to see if the shares are already mounted just mounting again which is a bit of a waste of time since your checking every minute. Use the mountpoint command to see if the share is mounted.
Does the samba server go offline constantly? Is this a laptop and you want to automatically connect when your on your home LAN? Using autofs might be a better choice since it will only mount when you access the share directory and automatically disconnect after at set idle time.
Well by the moment i am trying the follow with autofs :
#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage
#cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
# the following entries are samples to pique your imagination
#linux -ro,soft ftp.example.org:/pub/linux
#boot -fstype=ext2 :/dev/hda1
#floppy -fstype=auto :/dev/fd0
#floppy -fstype=ext2 :/dev/fd0
#e2floppy -fstype=ext2 :/dev/fd0
#jaz -fstype=ext2 :/dev/sdc1
#removable -fstype=ext2 :/dev/hdd
probably automounter would work better (see autofs). It will mount it only if needed and umount if the share is not used for a while.
Yes, nfs would be a better choice (instead of cifs).
By the way, there is a problem with the original approach. If ping fails the remote host is already down and probably you cannot successfully umount that share.
You are not configuring autofs correctly. Your using different configuration files and I believe you need to use the absolute path to the share name in your auto.misc file.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.