Author Topic: CIFS Mount External Share - Code for Lua start up.  (Read 18000 times)

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6157
  • Karma: +275/-69
  • "Less is more"
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #45 on: July 09, 2016, 05:39:27 am »
I'll be interested to see what your revised code is.

The command line is now:
Code: [Select]
mount -t cifs //192.168.1.111/Backups /nas -o user=XXX,pass=YYY,sec=ntlm

I found out somewhere that this works (for me, anyway.)  Who knows why?  It's one of those Unix dark arts things.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2463
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #46 on: July 09, 2016, 06:58:01 am »
You have to admire the 'dark arts' :)

Thanks @akbooer, so that would make the code to be the following.

Code: [Select]
-- @akbooer 2014-04-23
--

local function df ()
local info
local p = io.popen ("df",'r')
if p then info = p:read "*a"; p:close () end
return info
end

function cifsmount (x)
local function log (msg) luup.log (("cifsmount: '%s' %s"): format (x.device or '?', msg)) end
local df = df ()
if df: find (x.device, 1, true) then
log "already mounted"
else
local cmd = ("mount -t cifs //192.168.1.111/Backups /nas -o user=XXX,pass=YYY,sec=ntlm")
local ok, term, status = os.execute (cmd)
log ("mounted status: "..tostring(status))
if ok
then log ("mounted OK: "..tostring(ok))
elseif x.retry then luup.call_delay ("cifsmount", 60 * x.retry)
else log "failed to mount"
end
end
end

cifsmount
« Last Edit: July 09, 2016, 07:05:29 am by parkerc »

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6157
  • Karma: +275/-69
  • "Less is more"
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #47 on: July 09, 2016, 07:03:25 am »
So change the line

Code: [Select]
local cmd = ("mount -t cifs -o user=%s,pass=%s,nounix,noserverino %s %s"): format (x.user, x.pass, x.device, x.directory)

to

Code: [Select]
local cmd = ("mount -t cifs -o user=%s,pass=%s,sec=ntlm %s %s"): format (x.user, x.pass, x.device, x.directory)
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2463
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #48 on: July 09, 2016, 07:08:09 am »
Ok, thanks - I gave this a try

Code: [Select]
-- @akbooer 2014-04-23
--

local function df ()
local info
local p = io.popen ("df",'r')
if p then info = p:read "*a"; p:close () end
return info
end

function cifsmount (x)
local function log (msg) luup.log (("cifsmount: '%s' %s"): format (x.device or '?', msg)) end
local df = df ()
if df: find (x.device, 1, true) then
log "already mounted"
else
local cmd = ("mount -t cifs -o user=%s,pass=%s,sec=ntlm %s %s"): format (x.user, x.pass, x.device, x.directory)
local ok, term, status = os.execute (cmd)
log ("mounted status: "..tostring(status))
if ok
then log ("mounted OK: "..tostring(ok))
elseif x.retry then luup.call_delay ("cifsmount", 60 * x.retry)
else log "failed to mount"
end
end
end

local device = "//192.168.1.111/Backups"
local directory = "/nas"
local user = "user"
local pass = "password"


-- optional retry gives interval in minutes to retry failed mount attempt
cifsmount {user=user, pass=pass, device=device, directory=directory, retry=30}

But sadly no joy with df, even thought it suggests it went ok in the log.

Quote
50   07/09/16 12:10:26.317   luup_log:0: cifsmount: '//192.168.1.111/Backups' mounted status: nil <0x30e6a680>
50   07/09/16 12:10:26.318   luup_log:0: cifsmount: '//192.168.1.111/Backups' mounted OK: 65280 <0x30e6a680>
« Last Edit: July 09, 2016, 07:15:26 am by parkerc »

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6157
  • Karma: +275/-69
  • "Less is more"
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #49 on: July 09, 2016, 07:58:22 am »
Too bad.  Suggest you get it working at the command line level first.  It's apparently not a Lua / Vera thing.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2463
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #50 on: July 10, 2016, 04:28:57 pm »
Too bad.  Suggest you get it working at the command line level first.  It's apparently not a Lua / Vera thing.

Yep, and it's not playing nice  - it seems I may have bigger issues to sort out  ???

Quote
root@MiOS_30111521:~# mount -t cifs -o user=username,pass=password1,sec=ntlm //192.168.1.111/Backups /nas
mount: mounting //192.168.1.111/Backups on /nas failed: No such device

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6157
  • Karma: +275/-69
  • "Less is more"
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #51 on: July 10, 2016, 05:20:54 pm »
I notice that I have a '/' at the end of my device name for the mount, eg.

Code: [Select]
mount -t cifs /192.168.1.111/Backups/ /nas -o user=XXX,pass=YYY,sec=ntlm

does that, perchance, make any difference?
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2463
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #52 on: July 10, 2016, 06:10:09 pm »
Sadly not - but good thought :) - same error

Quote
mount: mounting //192.168.1.111/Backups/ on /nas failed: No such device

Offline barrytate01

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #53 on: July 21, 2017, 12:05:03 am »
Sadly not - but good thought :) - same error

Quote
mount: mounting //192.168.1.111/Backups/ on /nas failed: No such device

Did you ever get this to work?

Offline parkerc

  • Sr. Hero Member
  • ******
  • Posts: 2463
  • Karma: +35/-48
  • Life Moves Pretty Fast....
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #54 on: July 21, 2017, 01:01:05 am »
I now have this code in my Lua startup.

Code: [Select]
-- cifs mount for use during startup
-- big thanks to @akbooer 2014-04-23
--

local function df ()
  local info
  local p = io.popen ("df",'r')
  if p then info = p:read "*a"; p:close () end
  return info
end

local function cifsmount (x)
  local function log (msg) luup.log (("'%s' %s"): format (x.device or '', msg), 'mount') end
  local df = df ()
  if df: find (x.device, 1, true) then
    log "already mounted"
  else
    local cmd = table.concat {"mount -t cifs -o user=", x.user, ",pass=", x.pass, ",nounix,noserverino " , x.device, ' ', x.directory}
    local ok = os.execute (cmd)
    if ok
      then log "mounted OK"
      else log "failed to mount"
    end
  end
end

cifsmount {user="Username", pass="Password", device="//192.168.1.111/folder", directory="/nas"}

Let me know how you get on...

Offline bucko

  • Hero Member
  • *****
  • Posts: 651
  • Karma: +27/-8
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #55 on: December 25, 2017, 08:47:41 pm »
I tried this on my VeraPlus and ran it on test Lua. It failed

(I did change the last line to reflect my info)

First of all in putty I can only mount my cifs using..... mount -t cifs //xxx.xxx.xxx.xxx/Whisper /RT-AC87U -o user=xxx,pass=xxx,sec=ntlm

Could you give me another Lua code that can work with my actual mount command please?

EDIT:  I just ran this in AltUi test lua and the return result was  "[string "ALTUI - LuaRunHandler"]:3: attempt to call global 'df' (a nil value)"
This give you a clue?

Thanks


I now have this code in my Lua startup.

Code: [Select]
-- cifs mount for use during startup
-- big thanks to @akbooer 2014-04-23
--

local function df ()
  local info
  local p = io.popen ("df",'r')
  if p then info = p:read "*a"; p:close () end
  return info
end

local function cifsmount (x)
  local function log (msg) luup.log (("'%s' %s"): format (x.device or '', msg), 'mount') end
  local df = df ()
  if df: find (x.device, 1, true) then
    log "already mounted"
  else
    local cmd = table.concat {"mount -t cifs -o user=", x.user, ",pass=", x.pass, ",nounix,noserverino " , x.device, ' ', x.directory}
    local ok = os.execute (cmd)
    if ok
      then log "mounted OK"
      else log "failed to mount"
    end
  end
end

cifsmount {user="Username", pass="Password", device="//192.168.1.111/folder", directory="/nas"}

Let me know how you get on...
« Last Edit: December 25, 2017, 09:10:19 pm by bucko »
Vera 3, 40+ Fibaro relays & dimmers, IPUX cams, Elk M1 Gold, M1XEP, M1SP, XVOR, M1RB, Elk124, Monoprice HDMI matrix & 6 zone amp, Denon AVR, Panasonic A8000, BI DV,On Controls

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6157
  • Karma: +275/-69
  • "Less is more"
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #56 on: December 26, 2017, 03:54:53 am »
Where is the code? Is it all in Lua Test? It looks like you did not include the definition of the df() function.

To change the mount command string, just replace the ,nounix,noserverino with ,sec=ntlm
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline bucko

  • Hero Member
  • *****
  • Posts: 651
  • Karma: +27/-8
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #57 on: December 26, 2017, 09:10:04 am »
Where is the code? Is it all in Lua Test? It looks like you did not include the definition of the df() function.

To change the mount command string, just replace the ,nounix,noserverino with ,sec=ntlm

Sorry, Im not a coder so I don't know how to include this df function. I just copied the code from the thread.

But since DY does not "find" my mounted folder "Whisper" anyway, I suppose it's a moot point. Although I can mount my nas folder, (see previous post) , DY cannot find it to write to.
Vera 3, 40+ Fibaro relays & dimmers, IPUX cams, Elk M1 Gold, M1XEP, M1SP, XVOR, M1RB, Elk124, Monoprice HDMI matrix & 6 zone amp, Denon AVR, Panasonic A8000, BI DV,On Controls

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6157
  • Karma: +275/-69
  • "Less is more"
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #58 on: December 26, 2017, 11:20:28 am »
It was all in the code below, but if you didn?t copy ALL of the code then it might have been missing.

This is nothing to do with DataYours, it's all to do with Vera.  If a file system is accessible from Vera, then DataYours can write to it, given the right path.  If the disk is mounted already, then there?s absolutely no need for this code. 
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline bucko

  • Hero Member
  • *****
  • Posts: 651
  • Karma: +27/-8
Re: CIFS Mount External Share - Code for Lua start up.
« Reply #59 on: December 26, 2017, 07:58:37 pm »
Out of desperation, I deleted and re installed DY. I plugged in my same info in variables, and lo and behold, it is working. My external mount is being seen by DY and added 2 metrics for testing. But it appears all is working now.

Thanks for your help.
Vera 3, 40+ Fibaro relays & dimmers, IPUX cams, Elk M1 Gold, M1XEP, M1SP, XVOR, M1RB, Elk124, Monoprice HDMI matrix & 6 zone amp, Denon AVR, Panasonic A8000, BI DV,On Controls