cronfreebsdsmb

mount_smbfs fails in crontab with "mount_smbfs: unable to open connection: syserr = Authentication error"


I want a FreeBSD machine to mount a SMB share from a Linux server automatically after boot. Hence I wrote a script to run in the root crontab to mount it. I have set the require credential and IP on the /root/.nsmbrc and script runs fine on command line. However, it fails when being called from crontab with the following error.

mount_smbfs: unable to open connection: syserr = Authentication error

The content of the file /root/.nsmbrc

[default]
workgroup=WORKGROUP

[UBUNTU]
addr=192.168.1.20
charsets=UTF-8:UTF-8

[UBUNTU:FREEBSD]
password=[***trimmed***]

The mounting line

/usr/sbin/mount_smbfs -N -f 666 -d 777 //freebsd@ubuntu/share /net/ubuntu/share

How do I fix it?

Many thanks!


Solution

  • Try /etc/fstab, for example with something like:

    //u123@u123/foo /mnt/foo smbfs rw,late,-N 0 0
    

    If the option "late" is specified, the file system will be automatically mounted at a stage of system startup after remote mount points are mounted. (man fstab)

    Then in /etc/nsmb.conf you could have something like:

    [U123]
    addr=192.168.1.20
    retry_count=100
    timeout=30
    [U123:U123]
    password=secret