[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.
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.
#!/bin/bash
# $Id$
# This file must be executable to work! chmod 755!
key="$1"
# Note: create a cred file for each windows/Samba-Server in your network
# which requires password authentification. The file should contain
# exactly two lines:
# username=user
# password=*****
# Please don't use blank spaces to separate the equal sign from the
# user account name or password.
credfile="/etc/auto.smb.$key"
# Note: Use cifs instead of smbfs:
#mountopts="-fstype=cifs,file_mode=0644,dir_mode=0755,uid=user,gid=users"
mountopts="-fstype=cifs,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,uid=1000,gid=1000,domain=REDLOCAL"
smbclientopts=""
for P in /bin /sbin /usr/bin /usr/sbin
do
if [ -x $P/smbclient ]
then
SMBCLIENT=$P/smbclient
break
fi
done
[ -x $SMBCLIENT ] || exit 1
if [ -e "$credfile" ]
then
mountopts=$mountopts",credentials=$credfile"
smbclientopts="-A "$credfile
else
smbclientopts="-N"
fi
$SMBCLIENT $smbclientopts -gL $key 2>/dev/null \
| awk -v key="$key" -v opts="$mountopts" -F'|' -- '
BEGIN { ORS=""; first=1 }
/Disk/ { if (first) { print opts; first=0 };
gsub(/ /, "\\ ", $2);
sub(/\$/, "\\$", $2);
print " \\\n\t /" $2, "://" key "/" $2 }
END { if (!first) print "\n"; else exit 1 }
'
Code:
chmod 755 /etc/auto.cifs
/etc/auto.master
Quote:
#!/bin/bash
# $Id$
# This file must be executable to work! chmod 755!
key="$1"
# Note: create a cred file for each windows/Samba-Server in your network
# which requires password authentification. The file should contain
# exactly two lines:
# username=user
# password=*****
# Please don't use blank spaces to separate the equal sign from the
# user account name or password.
credfile="/etc/auto.smb.$key"
# Note: Use cifs instead of smbfs:
#mountopts="-fstype=cifs,file_mode=0644,dir_mode=0755,uid=user,gid=users"
mountopts="-fstype=cifs,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,uid=1000,gid=1000,domain=REDLOCAL"
smbclientopts=""
for P in /bin /sbin /usr/bin /usr/sbin
do
if [ -x $P/smbclient ]
then
SMBCLIENT=$P/smbclient
break
fi
done
#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
#ACTIVO#/misc /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
# "nosuid" and "nodev" options unless the "suid" and "dev"
# options are explicitly given.
#
#ACTIVO#/net -hosts
#
# Include /etc/auto.master.d/*.autofs
# To add an extra map using this mechanism you will need to add
# two configuration items - one /etc/auto.master.d/extra.autofs file
# (using the same line format as the auto.master file)
# and a separate mount map (e.g. /etc/auto.extra or an auto.extra NIS map)
# that is referred to by the extra.autofs file.
#
+dir:/etc/auto.master.d
#
# If you have fedfs set up and the related binaries, either
# built as part of autofs or installed from another package,
# uncomment this line to use the fedfs program map to access
# your fedfs mounts.
#/nfs4 /usr/sbin/fedfs-map-nfs4 nobind
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
Starting automounter version 5.1.8, master map auto.master
using kernel protocol version 5.05
lookup_nss_read_master: reading master files auto.master
do_init: parse(sun): init gathered global options: (null)
spawn_mount: mtab link detected, passing -n to mount
spawn_umount: mtab link detected, passing -n to mount
lookup_read_master: lookup(file): read entry +dir:/etc/auto.master.d
lookup_nss_read_master: reading master dir /etc/auto.master.d
lookup_read_master: lookup(dir): scandir: /etc/auto.master.d
lookup_read_master: lookup(file): read entry +auto.master
lookup_nss_read_master: reading master files auto.master
do_init: parse(sun): init gathered global options: (null)
lookup_read_master: lookup(file): read entry /-
master_do_mount: mounting /-
automount_path_to_fifo: fifo name /run/autofs.fifo--
lookup_nss_read_map: reading map file /etc/auto.cifs
Starting automounter version 5.1.8, master map auto.master
using kernel protocol version 5.05
lookup_nss_read_master: reading master files auto.master
do_init: parse(sun): init gathered global options: (null)
spawn_mount: mtab link detected, passing -n to mount
spawn_umount: mtab link detected, passing -n to mount
lookup_read_master: lookup(file): read entry +dir:/etc/auto.master.d
lookup_nss_read_master: reading master dir /etc/auto.master.d
lookup_read_master: lookup(dir): scandir: /etc/auto.master.d
lookup_read_master: lookup(file): read entry +auto.master
lookup_nss_read_master: reading master files auto.master
do_init: parse(sun): init gathered global options: (null)
lookup_read_master: lookup(file): read entry /-
/
master_do_mount: mounting /-
automount_path_to_fifo: fifo name /run/autofs.fifo--
lookup_nss_read_map: reading map file /etc/auto.cifs
do_init: parse(sun): init gathered global options: cifs
spawn_mount: mtab link detected, passing -n to mount
spawn_umount: mtab link detected, passing -n to mount
st_ready: st_ready(): state = 0 path /-
Starting automounter version 5.1.8, master map auto.master
using kernel protocol version 5.05
lookup_nss_read_master: reading master files auto.master
do_init: parse(sun): init gathered global options: (null)
spawn_mount: mtab link detected, passing -n to mount
spawn_umount: mtab link detected, passing -n to mount
lookup_read_master: lookup(file): read entry +dir:/etc/auto.master.d
lookup_nss_read_master: reading master dir /etc/auto.master.d
lookup_read_master: lookup(dir): scandir: /etc/auto.master.d
lookup_read_master: lookup(file): read entry +auto.master
lookup_nss_read_master: reading master files auto.master
do_init: parse(sun): init gathered global options: (null)
lookup_read_master: lookup(file): read entry /-
/
#!/bin/bash
# $Id$
# This file must be executable to work! chmod 755!
key="$1"
# Note: create a cred file for each windows/Samba-Server in your network
# which requires password authentification. The file should contain
# exactly two lines:
# username=user
# password=*****
# Please don't use blank spaces to separate the equal sign from the
# user account name or password.
credfile="/etc/auto.smb.$key"
# Note: Use cifs instead of smbfs:
#mountopts="-fstype=cifs,file_mode=0644,dir_mode=0755,uid=user,gid=users"
mountopts="-fstype=cifs,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,uid=1000,gid=1000,domain=REDLOCAL"
smbclientopts=""
for P in /bin /sbin /usr/bin /usr/sbin
do
if [ -x $P/smbclient ]
then
SMBCLIENT=$P/smbclient
break
fi
done
#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
#ACTIVO#/misc /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
# "nosuid" and "nodev" options unless the "suid" and "dev"
# options are explicitly given.
#
#ACTIVO#/net -hosts
#
# Include /etc/auto.master.d/*.autofs
# To add an extra map using this mechanism you will need to add
# two configuration items - one /etc/auto.master.d/extra.autofs file
# (using the same line format as the auto.master file)
# and a separate mount map (e.g. /etc/auto.extra or an auto.extra NIS map)
# that is referred to by the extra.autofs file.
#
+dir:/etc/auto.master.d
#
# If you have fedfs set up and the related binaries, either
# built as part of autofs or installed from another package,
# uncomment this line to use the fedfs program map to access
# your fedfs mounts.
#/nfs4 /usr/sbin/fedfs-map-nfs4 nobind
#
# Include central master map if it can be found using
# nsswitch sources.
#
Starting automounter version 5.1.8, master map auto.master
using kernel protocol version 5.05
lookup_nss_read_master: reading master files auto.master
do_init: parse(sun): init gathered global options: (null)
spawn_mount: mtab link detected, passing -n to mount
spawn_umount: mtab link detected, passing -n to mount
lookup_read_master: lookup(file): read entry +dir:/etc/auto.master.d
lookup_nss_read_master: reading master dir /etc/auto.master.d
lookup_read_master: lookup(dir): scandir: /etc/auto.master.d
lookup_read_master: lookup(file): read entry +auto.master
lookup_nss_read_master: reading master files auto.master
do_init: parse(sun): init gathered global options: (null)
lookup_read_master: lookup(file): read entry /-
/
master_do_mount: mounting /-
automount_path_to_fifo: fifo name /run/autofs.fifo--
lookup_nss_read_map: reading map file /etc/auto.cifs
do_init: parse(sun): init gathered global options: cifs
spawn_mount: mtab link detected, passing -n to mount
spawn_umount: mtab link detected, passing -n to mount
st_ready: st_ready(): state = 0 path /-
Code:
ls -als -R /cifs/
Quote:
/cifs/:
total 16
4 drwxr-xr-x 4 inukaze users 4096 may 8 23:57 ./
4 drwxr-xr-x 24 root root 4096 may 8 23:03 ../
4 drwxr-xr-x 3 root root 4096 may 8 23:57 Edna/
4 drwxr-xr-x 4 root root 4096 may 8 23:58 Geremia/
/cifs/Edna:
total 12
4 drwxr-xr-x 3 root root 4096 may 8 23:57 ./
4 drwxr-xr-x 4 inukaze users 4096 may 8 23:57 ../
4 drwxr-xr-x 2 root root 4096 may 8 23:57 SSD-Gaby/
/cifs/Edna/SSD-Gaby:
total 8
4 drwxr-xr-x 2 root root 4096 may 8 23:57 ./
4 drwxr-xr-x 3 root root 4096 may 8 23:57 ../
/cifs/Geremia:
total 16
4 drwxr-xr-x 4 root root 4096 may 8 23:58 ./
4 drwxr-xr-x 4 inukaze users 4096 may 8 23:57 ../
4 drwxr-xr-x 2 root root 4096 may 8 23:57 Inukaze/
4 drwxr-xr-x 2 root root 4096 may 8 23:58 Temporal/
/cifs/Geremia/Inukaze:
total 8
4 drwxr-xr-x 2 root root 4096 may 8 23:57 ./
4 drwxr-xr-x 4 root root 4096 may 8 23:58 ../
/cifs/Geremia/Temporal:
total 8
4 drwxr-xr-x 2 root root 4096 may 8 23:58 ./
4 drwxr-xr-x 4 root root 4096 may 8 23:58 ../
i think is better remove autofs, looks like really does not work, because i try like
/cifs/:
total 16
4 drwxrwxrwx 4 inukaze users 4096 may 9 00:48 ./
4 drwxr-xr-x 25 root root 4096 may 9 00:59 ../
4 drwxrwxrwx 3 inukaze users 4096 may 9 00:53 Edna/
4 drwxrwxrwx 4 inukaze users 4096 may 9 00:53 Geremia/
/cifs/Edna:
total 8
4 drwxrwxrwx 3 inukaze users 4096 may 9 00:53 ./
4 drwxrwxrwx 4 inukaze users 4096 may 9 00:48 ../
0 drwxr-xr-x 2 root root 0 may 9 00:59 SSD-Gaby/
ls: no se puede abrir el directorio '/cifs/Edna/SSD-Gaby': No existe el fichero o el directorio
/cifs/Geremia:
total 8
4 drwxrwxrwx 4 inukaze users 4096 may 9 00:53 ./
4 drwxrwxrwx 4 inukaze users 4096 may 9 00:48 ../
0 drwxr-xr-x 2 root root 0 may 9 00:59 Inukaze/
0 drwxr-xr-x 2 root root 0 may 9 00:59 Temporal/
ls: no se puede abrir el directorio '/cifs/Geremia/Inukaze': No existe el fichero o el directorio
ls: no se puede abrir el directorio '/cifs/Geremia/Temporal': No existe el fichero o el directorio
automount -f -v --debug add the follow lines to output :
Quote:
handle_packet: type = 5
handle_packet_missing_direct: token 266, name /cifs/Edna/SSD-Gaby, request pid 6969
attempting to mount entry /cifs/Edna/SSD-Gaby
lookup_mount: lookup(file): looking up /cifs/Edna/SSD-Gaby
lookup_mount: lookup(file): /cifs/Edna/SSD-Gaby -> -fstype=cifs,credentials=/home/inukaze/.smb-credenciales,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,uid=1000,gid=1000,domain=REDLOCAL 192.168.1.11:/SSD-Gaby
parse_mount: parse(sun): expanded entry: -fstype=cifs,credentials=/home/inukaze/.smb-credenciales,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,uid=1000,gid=1000,domain=REDLOCAL 192.168.1.11:/SSD-Gaby
parse_mount: parse(sun): gathered options: fstype=cifs,credentials=/home/inukaze/.smb-credenciales,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,uid=1000,gid=1000,domain=REDLOCAL
parse_mount: parse(sun): dequote("192.168.1.11:/SSD-Gaby") -> 192.168.1.11:/SSD-Gaby
parse_mount: parse(sun): core of entry: options=fstype=cifs,credentials=/home/inukaze/.smb-credenciales,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,uid=1000,gid=1000,domain=REDLOCAL , loc=192.168.1.11:/SSD-Gaby
sun_mount: parse(sun): mounting root /cifs/Edna/SSD-Gaby, mountpoint /cifs/Edna/SSD-Gaby, what 192.168.1.11:/SSD-Gaby, fstype cifs, options credentials=/home/inukaze/.smb-credenciales,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,uid=1000,gid=1000,domain=REDLOCAL
do_mount: 192.168.1.11:/SSD-Gaby /cifs/Edna/SSD-Gaby type cifs options credentials=/home/inukaze/.smb-credenciales,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,uid=1000,gid=1000,domain=REDLOCAL using module generic
mount_mount: mount(generic): calling mkdir_path /cifs/Edna/SSD-Gaby
mount(generic): calling mount -t cifs -o credentials=/home/inukaze/.smb-credenciales,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,uid=1000,gid=1000,domain=REDLOCAL 192.168.1.11:/SSD-Gaby /cifs/Edna/SSD-Gaby
spawn_mount: mtab link detected, passing -n to mount
>> mount.cifs: bad UNC (192.168.1.11:/SSD-Gaby)
mount(generic): failed to mount 192.168.1.11:/SSD-Gaby (type cifs) on /cifs/Edna/SSD-Gaby
dev_ioctl_send_fail: token = 266
failed to mount /cifs/Edna/SSD-Gaby
handle_packet: type = 5
handle_packet_missing_direct: token 267, name /cifs/Geremia/Inukaze, request pid 6969
attempting to mount entry /cifs/Geremia/Inukaze
lookup_mount: lookup(file): looking up /cifs/Geremia/Inukaze
lookup_mount: lookup(file): /cifs/Geremia/Inukaze -> -fstype=cifs,-vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,domain=REDLOCAL 192.168.1.10:/Inukaze
parse_mount: parse(sun): expanded entry: -fstype=cifs,-vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,domain=REDLOCAL 192.168.1.10:/Inukaze
parse_mount: parse(sun): gathered options: fstype=cifs,-vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,domain=REDLOCAL
parse_mount: parse(sun): dequote("192.168.1.10:/Inukaze") -> 192.168.1.10:/Inukaze
parse_mount: parse(sun): core of entry: options=fstype=cifs,-vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,domain=REDLOCAL, loc=192.168.1.10:/Inukaze
sun_mount: parse(sun): mounting root /cifs/Geremia/Inukaze, mountpoint /cifs/Geremia/Inukaze, what 192.168.1.10:/Inukaze, fstype cifs, options -vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,domain=REDLOCAL
do_mount: 192.168.1.10:/Inukaze /cifs/Geremia/Inukaze type cifs options -vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,domain=REDLOCAL using module generic
mount_mount: mount(generic): calling mkdir_path /cifs/Geremia/Inukaze
mount(generic): calling mount -t cifs -o -vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,domain=REDLOCAL 192.168.1.10:/Inukaze /cifs/Geremia/Inukaze
spawn_mount: mtab link detected, passing -n to mount
>> mount.cifs: bad UNC (192.168.1.10:/Inukaze)
mount(generic): failed to mount 192.168.1.10:/Inukaze (type cifs) on /cifs/Geremia/Inukaze
dev_ioctl_send_fail: token = 267
failed to mount /cifs/Geremia/Inukaze
handle_packet: type = 5
handle_packet_missing_direct: token 268, name /cifs/Geremia/Temporal, request pid 6969
attempting to mount entry /cifs/Geremia/Temporal
lookup_mount: lookup(file): looking up /cifs/Geremia/Temporal
lookup_mount: lookup(file): /cifs/Geremia/Temporal -> -fstype=cifs,-vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,domain=REDLOCAL 192.168.1.10:/Temporal
parse_mount: parse(sun): expanded entry: -fstype=cifs,-vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,domain=REDLOCAL 192.168.1.10:/Temporal
parse_mount: parse(sun): gathered options: fstype=cifs,-vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,domain=REDLOCAL
parse_mount: parse(sun): dequote("192.168.1.10:/Temporal") -> 192.168.1.10:/Temporal
parse_mount: parse(sun): core of entry: options=fstype=cifs,-vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,domain=REDLOCAL, loc=192.168.1.10:/Temporal
sun_mount: parse(sun): mounting root /cifs/Geremia/Temporal, mountpoint /cifs/Geremia/Temporal, what 192.168.1.10:/Temporal, fstype cifs, options -vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,domain=REDLOCAL
do_mount: 192.168.1.10:/Temporal /cifs/Geremia/Temporal type cifs options -vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,domain=REDLOCAL using module generic
mount_mount: mount(generic): calling mkdir_path /cifs/Geremia/Temporal
mount(generic): calling mount -t cifs -o -vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,domain=REDLOCAL 192.168.1.10:/Temporal /cifs/Geremia/Temporal
spawn_mount: mtab link detected, passing -n to mount
>> mount.cifs: bad UNC (192.168.1.10:/Temporal)
mount(generic): failed to mount 192.168.1.10:/Temporal (type cifs) on /cifs/Geremia/Temporal
dev_ioctl_send_fail: token = 268
failed to mount /cifs/Geremia/Temporal
It would take the output of the command in parentheses and try to run it. You can't see the difference because by chance your sudo/mount command doesn't output anything to stdout to be run. Let's try another command, 'echo -n l; echo s' outputs 'ls'. Guess what this command does:
Code:
$(echo -n l; echo s)
It runs command 'ls'.
Maybe you have copied the line from somewhere not realizing that the dollar sign in the beginning is the bash command prompt, not to be included in the line in a script. Without the dollar sign
Code:
(commands ...) &
would be ok to run commands in a backgrounded subshell and the dollar sign in front was an accidentally copied command prompt?
I haven't used CIFS with automount myself, only NFS. However, during the years there have been different default behavior for automounted NFS directories.
Earlier years, directories where not shown with ls until mounted and they were not mounted until entered.
Later years directories listed in automount maps has been shown before entered, I don't think that I have changed any setting to accomplish that.
Then there is the /net directory which is kind of special, example:
Code:
nazgul:/tmp> /usr/sbin/showmount -e balrog
Export list for balrog:
/mnt/hd *
nazgul:/tmp> ls /net
sauron/
nazgul:/tmp> ls /net/balrog
mnt/
nazgul:/tmp> ls /net
balrog/ sauron/
nazgul:/tmp>
The /net directory can mount any NFS server in the network, but it doesn't automatically portscan every server in the network, it will only mount servers when asked to.
However, looking at /etc/auto.net you can see that it does only support NFS servers, not CIFS servers.
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/
i have write the file /etc/rc.d/rc.cifshare with the follow content :
Code:
#!/bin/sh
cifs_start() {
while :
do
Geremia=$(ping -4 -c 1 192.168.1.10 | grep -oP '\d+ received' | cut -d' ' -f1)
Edna=$(ping -4 -c 1 192.168.1.11 | grep -oP '\d+ received' | cut -d' ' -f1)
if [[ "$Edna" == "1" ]]; then
PC="Edna"
IP="192.168.1.11"
Carpeta="SSD-Gaby"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [ -z "$Montura" ]; then
mkdir -p "/cifs/$PC/$Carpeta"
mount -t cifs "//$IP/$Carpeta" "/cifs/$PC/$Carpeta" -o "credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL"
fi
fi
if [[ "$Edna" == "0" ]]; then
PC="Edna"
IP="192.168.1.11"
Carpeta="SSD-Gaby"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
fi
if [[ "$Geremia" == "1" ]]; then
PC="Geremia"
IP="192.168.1.10"
Carpeta="Inukaze-en-Familia"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [ -z "$Montura" ]; then
mkdir -p "/cifs/$PC/$Carpeta"
mount -t cifs "//$IP/$Carpeta" "/cifs/$PC/$Carpeta" -o "vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL"
fi
Carpeta="Josmar"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [ -z "$Montura" ]; then
mkdir -p "/cifs/$PC/$Carpeta"
mount -t cifs "//$IP/$Carpeta" "/cifs/$PC/$Carpeta" -o "vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL"
fi
Carpeta="Inukaze"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [ -z "$Montura" ]; then
mkdir -p "/cifs/$PC/$Carpeta"
mount -t cifs "//$IP/$Carpeta" "/cifs/$PC/$Carpeta" -o "vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL"
fi
Carpeta="Temporal"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [ -z "$Montura" ]; then
mkdir -p "/cifs/$PC/$Carpeta"
mount -t cifs "//$IP/$Carpeta" "/cifs/$PC/$Carpeta" -o "vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL"
fi
fi
if [[ "$Geremia" == "0" ]]; then
PC="Geremia"
IP="192.168.1.10"
Carpeta="Inukaze-en-Familia"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
Carpeta="Josmar"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
Carpeta="Inukaze"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
Carpeta="Temporal"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
fi
sleep 60
done
}
cifs_stop() {
Geremia=$(ping -4 -c 1 192.168.1.10 | grep -oP '\d+ received' | cut -d' ' -f1)
Edna=$(ping -4 -c 1 192.168.1.11 | grep -oP '\d+ received' | cut -d' ' -f1)
PC="Edna"
IP="192.168.1.11"
Carpeta="SSD-Gaby"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
PC="Geremia"
IP="192.168.1.10"
Carpeta="Inukaze-en-Familia"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
Carpeta="Josmar"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
Carpeta="Inukaze"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
Carpeta="Temporal"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
}
case "$1" in
start)
cifs_start &
;;
stop)
cifs_stop &
;;
*)
echo "Usage: $0 start|stop"
exit 1
;;
esac
exit 0
Code:
chmod 755 /etc/rc.d/rc.cifshare
Well that solve the thing with start [note stop does not fine XD], is not the most optimized method but works XD
i still i don't think how i can just use "status" for check if this script is running or not.
PID_FILE="/run/rc_cifshare.pid"
cifs_start() {
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null; then
echo "Service is already runing with PID $PID"
return
else
# Clean up invalid PID file
rm -f "$PID_FILE"
fi
fi
# Store the current process ID
echo $$ > "$PID_FILE"
(
while :
#continue...your script
and finish like this:
Code:
cifs_stop() {
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null; then
kill $PID
fi
rm -f "$PID_FILE"
else
echo "Service is not running"
fi
}
case "$1" in
start)
cifs_start
;;
stop)
cifs_stop
;;
status)
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null; then
echo "Service is running with PID $PID"
else
echo "Service is not running, but PID file exists"
rm -f "$PID_FILE"
fi
else
echo "Service is not running"
fi
;;
*)
echo "Usage: $0 start|stop|status"
exit 1
;;
esac
exit 0
Your using /bin/sh i.e posix shell which means that [[ ]] is not valid syntax. The script should not work as posted.
If cifs_start is truly running as an infinite loop then cifs_stop may work but then the shares will just be mounted again or tested again at the next minute. Typically a startup script does not run as a loop.
It would take the output of the command in parentheses and try to run it. You can't see the difference because by chance your sudo/mount command doesn't output anything to stdout to be run. Let's try another command, 'echo -n l; echo s' outputs 'ls'. Guess what this command does:
Code:
$(echo -n l; echo s)
It runs command 'ls'.
the "$(command1 ; command2) &" part is some i determinate by the hard way, making scripts ever works on every version of bash on any posix operating system compatible to make ever works. becuase with "command1 ; command2 &" on some versions of apple mac os x, just run one command or none and does not matter if "&" is at the end, the script stuck on there.
Maybe you have copied the line from somewhere not realizing that the dollar sign in the beginning is the bash command prompt, not to be included in the line in a script. Without the dollar sign
Code:
(commands ...) &
would be ok to run commands in a backgrounded subshell and the dollar sign in front was an accidentally copied command prompt?
no i never had copiad the line from somewhere, that is something i determinate by a lot of mistake making a script work under any bash version on GNU/Linux, GNU/Mach, GNU/Hurd, GNU/kFreeBSD, Apple Mac OS X, FreeBSD, GhostBSD, PCBSD.
because exist a common strict form of write code in bash works on any version, but that are not explained anywhere, because the syntax can works under GNU/Linux not necesary works under Apple Mac OS X, or in a Linux without GNU Operating System.
when you write " $() " is just for the command(s) not get out that controlled limit, on some operating system when you not specify a limit, can start a mess like write an infinity log inside /spool and you get a file with 1TB size in just 1 minute, because the command does not have nothing to limit it, for experiencies like that i had start write $(command1 ; command2) because with this the weird things does not happend, on GNU/Linux does have diferences if you write $(command1 ; command2) or"command1 ; command2) but on anothers so, yes.
PID_FILE="/run/rc_cifshare.pid"
cifs_start() {
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null; then
echo "Service is already runing with PID $PID"
return
else
# Clean up invalid PID file
rm -f "$PID_FILE"
fi
fi
# Store the current process ID
echo $$ > "$PID_FILE"
(
while :
#continue...your script
and finish like this:
Code:
cifs_stop() {
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null; then
kill $PID
fi
rm -f "$PID_FILE"
else
echo "Service is not running"
fi
}
case "$1" in
start)
cifs_start
;;
stop)
cifs_stop
;;
status)
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null; then
echo "Service is running with PID $PID"
else
echo "Service is not running, but PID file exists"
rm -f "$PID_FILE"
fi
else
echo "Service is not running"
fi
;;
*)
echo "Usage: $0 start|stop|status"
exit 1
;;
esac
exit 0
might works...
i dont understand in where i should add the parts you had write. i am thing on the stop maybe i should use "break" or something.
* my stop is not working i expect, the infinite loop still working
* for reasons i dont understand the mount /cifs/Geremia/Inukaze is the unique is not umounted.
* which should a better idea :
a) all in one file /etc/rc.d/rc.cifshare [ this does not work during boot ]
b) two files, /etc/rc.d/rc.cifshare just for act like daemon/service and the script with infine loop and the non-working stop statament XD.
Code:
#!/bin/sh
PID_FILE="/run/rc_cifshare.pid"
unset cifs_stop
unset cifs_start
cifs_stop() {
IP="192.168.1.10" ; PC="Geremia"
Carpeta="Inukaze" ; Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1) ; if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then umount -f -l "/cifs/$PC/$Carpeta"; fi
Carpeta="Inukaze-en-Familia" ; Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1) ; if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then umount -f -l "/cifs/$PC/$Carpeta"; fi
Carpeta="Josmar" ; Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1) ; if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then umount -f -l "/cifs/$PC/$Carpeta"; fi
Carpeta="Temporal" ; Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1) ; if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then umount -f -l "/cifs/$PC/$Carpeta"; fi
IP="192.168.1.11" ; PC="Edna"
Carpeta="SSD-Gaby" ; Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1) ; if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then umount -f -l "/cifs/$PC/$Carpeta"; fi
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null; then
kill -s KILL "$PID"
fi
rm -f "$PID_FILE"
else
echo "Service is not running"
fi
}
cifs_start() {
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null; then
echo "Service is already runing with PID $PID"
return
else
# Clean up invalid PID file
rm -f "$PID_FILE"
fi
fi
# Store the current process ID
echo $$ > "$PID_FILE"
(
while :
do
Entrada=$(echo "$1" | tr -s '[:upper:]' '[:lower:]')
if [[ "$Entrada" == "stop" ]]
then
cifs_stop
break
fi
Geremia=$(ping -4 -c 1 192.168.1.10 | grep -oP '\d+ received' | cut -d' ' -f1)
Edna=$(ping -4 -c 1 192.168.1.11 | grep -oP '\d+ received' | cut -d' ' -f1)
if [[ "$Edna" == "1" ]]; then
PC="Edna"
IP="192.168.1.11"
Carpeta="SSD-Gaby"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [ -z "$Montura" ]; then
mkdir -p "/cifs/$PC/$Carpeta"
mount -t cifs "//$IP/$Carpeta" "/cifs/$PC/$Carpeta" -o "credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL"
fi
fi
if [[ "$Edna" == "0" ]]; then
PC="Edna"
IP="192.168.1.11"
Carpeta="SSD-Gaby"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
fi
if [[ "$Geremia" == "1" ]]; then
PC="Geremia"
IP="192.168.1.10"
Carpeta="Inukaze"
#Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1 | sed 's/-en-Familia//g')
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1 | tail -n 1)
if [ -z "$Montura" ]; then
mkdir -p "/cifs/$PC/$Carpeta"
mount -t cifs "//$IP/$Carpeta" "/cifs/$PC/$Carpeta" -o "vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL"
fi
Carpeta="Inukaze-en-Familia"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [ -z "$Montura" ]; then
mkdir -p "/cifs/$PC/$Carpeta"
mount -t cifs "//$IP/$Carpeta" "/cifs/$PC/$Carpeta" -o "vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL"
fi
Carpeta="Josmar"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [ -z "$Montura" ]; then
mkdir -p "/cifs/$PC/$Carpeta"
mount -t cifs "//$IP/$Carpeta" "/cifs/$PC/$Carpeta" -o "vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL"
fi
Carpeta="Temporal"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [ -z "$Montura" ]; then
mkdir -p "/cifs/$PC/$Carpeta"
mount -t cifs "//$IP/$Carpeta" "/cifs/$PC/$Carpeta" -o "vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL"
fi
fi
if [[ "$Geremia" == "0" ]]; then
PC="Geremia"
IP="192.168.1.10"
Carpeta="Inukaze"
#Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1 | sed 's/-en-Familia//g')
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1 | tail -n 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
# Force Manual Mount :
# mount -t cifs //192.168.1.10/Inukaze /cifs/Geremia/Inukaze -o vers=1.0,credentials=/home/inukaze/.smb-credenciales,uid=1000,gid=1000,rw,nounix,iocharset=utf8,file_mode=0777,dir_mode=0777,domain=REDLOCAL
Carpeta="Inukaze-en-Familia"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
Carpeta="Josmar"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
Carpeta="Temporal"
Montura=$(findmnt | grep "//$IP/$Carpeta" | awk '{print $1,$2}' | cut -b 7- | cut -d " " -f 1)
if [[ "$Montura" == "/cifs/$PC/$Carpeta" ]]; then
umount -f -l "/cifs/$PC/$Carpeta"
fi
fi
sleep 60
done
)
}
case "$1" in
start)
cifs_start
;;
stop)
cifs_stop
;;
status)
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if ps -p "$PID" > /dev/null; then
echo "Service is running with PID $PID"
else
echo "Service is not running, but PID file exists"
rm -f "$PID_FILE"
fi
else
echo "Service is not running"
fi
;;
*)
echo "Usage: $0 start|stop|status"
exit 1
;;
esac
exit 0
yes, shellcheck reports this posix syntax issue (In POSIX sh, [[ ]] is undefined.) and other problems too.
Actually ( ) means a new process (subshell) and your while loop is running inside it. kill -s kill will terminate $pid, but not the subshell (as far as I see). By the way, would be better to use sigterm instead of sigkill. Anyway, you need to optimize this script by using functions instead of repeating the same line(s) again and again. Also would be better to format it (use for example shfmt) to make it more readable.
If you put cifs_start in the background it is going to have a different pid from the script itself which could be the reason your cifs_stop function code in #27 isn't working.
Code:
start)
cifs_start &
echo $! > "$PID_FILE"
;;
Even though you are running cifs_stop in post #27 it will not stop the start loop unless you kill that running process.
You maybe able to simply your stop script with just the following. I assume no other cifs shares are mounted.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.