LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 05-07-2024, 02:21 PM   #1
inukaze
Member
 
Registered: Feb 2011
Location: Venezuela - Caracas
Distribution: Slackware64 14.2, Slackware 14.2, Gentoo, Devuan, gNewSense, GoboLinux, Leeenux, Porteus
Posts: 289

Rep: Reputation: 26
Question 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.

i already try to put on sudoers :
Code:
inukaze Slack64 = NOPASSWD: /usr/bin/mount, /usr/bin/umount, /usr/bin/ifconfig, /usr/bin/mkdir, /bin/mkdir, /sbin/mount, /sbin/umount
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.

Last edited by inukaze; 05-07-2024 at 02:23 PM.
 
Old 05-07-2024, 02:39 PM   #2
LuckyCyborg
Senior Member
 
Registered: Mar 2010
Posts: 3,549

Rep: Reputation: 3402Reputation: 3402Reputation: 3402Reputation: 3402Reputation: 3402Reputation: 3402Reputation: 3402Reputation: 3402Reputation: 3402Reputation: 3402Reputation: 3402
Quote:
Originally Posted by inukaze View Post
Hi there

* i want make a « Daemon » to ...
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.
 
1 members found this post helpful.
Old 05-07-2024, 05:08 PM   #3
rizitis
Member
 
Registered: Mar 2009
Location: Greece,Crete
Distribution: Slackware64-current, Slint
Posts: 676
Blog Entries: 1

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
I believe you need something like these:

Add this in rc.local:
Code:
if [ -x /etc/rc.d/rc.pingtomount ]; then
    /etc/rc.d/rc.pingtomount start
fi
I left sudo in script but dont think you need sudo when you start from rc.local the daemon but you know better... visudo:
Code:
inukaze ALL=(ALL) NOPASSWD: /bin/mount, /bin/umount
modify attachments for your needs and place them to the right place.
One attachment is the script and the other rc.pingmount for /etc/rc.d/
Attached Files
File Type: txt rc.pingmount.txt (934 Bytes, 8 views)
File Type: txt pingtomount.txt (1.4 KB, 9 views)
 
1 members found this post helpful.
Old 05-07-2024, 06:36 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,760

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
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.
 
1 members found this post helpful.
Old 05-08-2024, 12:40 AM   #5
henca
Member
 
Registered: Aug 2007
Location: Linköping, Sweden
Distribution: Slackware
Posts: 990

Rep: Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674Reputation: 674
Quote:
Originally Posted by michaelk View Post
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.

regards Henrik
 
Old 05-08-2024, 01:49 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,976

Rep: Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336
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 .....) &
???
 
1 members found this post helpful.
Old 05-08-2024, 04:41 AM   #7
viel
Member
 
Registered: Jul 2021
Location: Arcadia
Distribution: Slackware
Posts: 50

Rep: Reputation: Disabled
Post

Hi,

Maybe a while loop can replace the watch command
Code:
while [ $(date | cut -d" " -f5 | cut -d: -f3) != 00 ] ; do sleep 1 ; done && echo "run ping 1"

while [ $(date | cut -d" " -f5 | cut -d: -f3) != 30 ] ; do sleep 1 ; done && echo "run ping 2"
Duno if that will be efficient like watch, maybe you can do some trys.

For sudo you can make the script on /usr/local/bin/pingmount.sh with permissions only exec or read and exec.
Code:
-rwxr-xr-x 1 root root /usr/local/bin/pingmount.sh
and on sudoers
Code:
inukaze ALL=(ALL) NOPASSWD: /usr/local/bin/pingmount.sh
to limit the user interactions with mount.

and make a cron from inukaze ... if you run every minute you don't need the watch.
Code:
* * * * * 'sudo /usr/local/bin/pingmount.sh'

There are lot of ways, easy <--> secure <--> efficient all good. Depends on what you are looking for.

Edited: with sshfs there are options to reconnect too,like:
Code:
sshfs -o allow_other,default_permissions,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 root@192.168.1.10:/Inukaze /mnt/Geremia/Inukaze
But you need config ssh id if don't want to use passwords.

Hope that helps.

Viel.

Last edited by viel; 05-08-2024 at 10:40 AM.
 
Old 05-08-2024, 09:34 AM   #8
inukaze
Member
 
Registered: Feb 2011
Location: Venezuela - Caracas
Distribution: Slackware64 14.2, Slackware 14.2, Gentoo, Devuan, gNewSense, GoboLinux, Leeenux, Porteus
Posts: 289

Original Poster
Rep: Reputation: 26
Quote:
Originally Posted by pan64 View Post
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.

well i am going to see autofs manual.
 
Old 05-08-2024, 10:32 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,760

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
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.
 
Old 05-08-2024, 11:19 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,976

Rep: Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336Reputation: 7336
Quote:
Originally Posted by michaelk View Post
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.
 
Old 05-08-2024, 04:33 PM   #11
inukaze
Member
 
Registered: Feb 2011
Location: Venezuela - Caracas
Distribution: Slackware64 14.2, Slackware 14.2, Gentoo, Devuan, gNewSense, GoboLinux, Leeenux, Porteus
Posts: 289

Original Poster
Rep: Reputation: 26
Question

Quote:
Originally Posted by michaelk View Post
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 :

Code:
chmod a+x /etc/rc.d/rc.autofs
nano /etc/auto.master
at the end of file i add :
Quote:
/- /etc/auto.mount
Code:
touch /etc/credentials
chmod 600 /etc/credentials
nano /etc/credentials
The temporal content of /etc/credentials
Quote:
username=test
password=t3st
Code:
nano /etc/auto.misc
Quote:
#
# 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

Inukaze --fstype=cifs,vers=1.0,credentials=/etc/credentials,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL ://192.168.1.10/Inukaze
Inukaze-en-Familia --fstype=cifs,vers=1.0,credentials=/etc/credentials,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL ://192.168.1.10/Inukaze-en-Familia
Temporal --fstype=cifs,vers=1.0,credentials=/etc/credentials,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL ://192.168.1.10/Temporal
Josmar --fstype=cifs,vers=1.0,credentials=/etc/credentials,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL ://192.168.1.10/Josmar
SSD-Gaby --fstype=cifs,credentials=/etc/credentials,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL ://192.168.1.11/SSD-Gaby
Code:
automount -f -v
and well the /net and /misc folder are empty
Click image for larger version

Name:	autofs-empty.png
Views:	6
Size:	79.5 KB
ID:	42791


what i am doing wrong?
 
Old 05-08-2024, 04:36 PM   #12
inukaze
Member
 
Registered: Feb 2011
Location: Venezuela - Caracas
Distribution: Slackware64 14.2, Slackware 14.2, Gentoo, Devuan, gNewSense, GoboLinux, Leeenux, Porteus
Posts: 289

Original Poster
Rep: Reputation: 26
Quote:
Originally Posted by pan64 View Post
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 .....) &
???
Manual mount of cifs type filesystem
 
Old 05-08-2024, 05:02 PM   #13
inukaze
Member
 
Registered: Feb 2011
Location: Venezuela - Caracas
Distribution: Slackware64 14.2, Slackware 14.2, Gentoo, Devuan, gNewSense, GoboLinux, Leeenux, Porteus
Posts: 289

Original Poster
Rep: Reputation: 26
Question

Quote:
Originally Posted by viel View Post
Hi,

Maybe a while loop can replace the watch command
Code:
while [ $(date | cut -d" " -f5 | cut -d: -f3) != 00 ] ; do sleep 1 ; done && echo "run ping 1"

while [ $(date | cut -d" " -f5 | cut -d: -f3) != 30 ] ; do sleep 1 ; done && echo "run ping 2"
Duno if that will be efficient like watch, maybe you can do some trys.

For sudo you can make the script on /usr/local/bin/pingmount.sh with permissions only exec or read and exec.
Code:
-rwxr-xr-x 1 root root /usr/local/bin/pingmount.sh
and on sudoers
Code:
inukaze ALL=(ALL) NOPASSWD: /usr/local/bin/pingmount.sh
to limit the user interactions with mount.

and make a cron from inukaze ... if you run every minute you don't need the watch.
Code:
* * * * * 'sudo /usr/local/bin/pingmount.sh'

There are lot of ways, easy <--> secure <--> efficient all good. Depends on what you are looking for.

Edited: with sshfs there are options to reconnect too,like:
Code:
sshfs -o allow_other,default_permissions,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3 root@192.168.1.10:/Inukaze /mnt/Geremia/Inukaze
But you need config ssh id if don't want to use passwords.

Hope that helps.

Viel.
i prefer sshfs method, can you sayme in which configuration file or startup script i should put that ?
 
Old 05-08-2024, 05:09 PM   #14
inukaze
Member
 
Registered: Feb 2011
Location: Venezuela - Caracas
Distribution: Slackware64 14.2, Slackware 14.2, Gentoo, Devuan, gNewSense, GoboLinux, Leeenux, Porteus
Posts: 289

Original Poster
Rep: Reputation: 26
Quote:
Originally Posted by rizitis View Post
I believe you need something like these:

Add this in rc.local:
Code:
if [ -x /etc/rc.d/rc.pingtomount ]; then
    /etc/rc.d/rc.pingtomount start
fi
I left sudo in script but dont think you need sudo when you start from rc.local the daemon but you know better... visudo:
Code:
inukaze ALL=(ALL) NOPASSWD: /bin/mount, /bin/umount
modify attachments for your needs and place them to the right place.
One attachment is the script and the other rc.pingmount for /etc/rc.d/
The daemon is autostop after some seconds :v
 
Old 05-08-2024, 05:22 PM   #15
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,760

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
sshfs is a fuse filesystem that uses the ssh/sftp subsystem. You can mount it manually, from a bash login script, autofs or even just fstab.

https://wiki.archlinux.org/title/SSHFS

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.

/- /etc/auto.mount
versus
/etc/auto.misc

https://wiki.archlinux.org/title/autofs

Last edited by michaelk; 05-08-2024 at 05:27 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting crontab to ping gateway every minute moses0404 Linux - Newbie 10 02-25-2013 09:29 AM
[SOLVED] Configured Cron job executed every hour is instead executed every minute for 10m markings Linux - Software 4 05-13-2012 05:43 PM
I cannot ping with command 'ping IP' address but can ping with 'ping IP -I eth0' sanketmlad Linux - Networking 2 07-15-2011 05:32 AM
crontab: minute hour or hour minute anon091 Linux - Newbie 2 11-04-2009 03:09 PM
want to run program every minute, crontab???? poj Linux - General 4 09-19-2005 04:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration