• The forum software that supports hummy.tv has been upgraded to XenForo 2.3!

    Please bear with us as we continue to tweak things, and feel free to post any questions, issues or suggestions in the upgrade thread.

Is it possible to trigger NASMount to mount a NAS when that NAS starts up?

Never heard of that libation. I'm not rich, frequently cold and would prefer something hoppy from the Klosterbrauerei Andechs.
 
It's your funeral, not ours. Do it whatever way you like. We can only advise (and any advice given is purely voluntary – there is no beef).
What's that about my funeral? Do you know something I don't :eek:

Perhaps it does make some sense, if you mean the NAS script Telnets into the Foxsat to send the command for the Foxsat to run. But it doesn't really account for error responses, and the Telnet login credentials will have to be stored in the NAS script in the clear (if security bothers you). A significant reason for not injecting commands to a remote system are the security implications: file access permissions are lower risk than command access.
I have generated a key pair on the NAS and sent it to the Foxsat
ssh-copy-id -i ~/.ssh/id_rsa.pub Humax@ip.of.the.foxsat
That means I can SSH into the Foxsat with no password. SSH is encrypted so no sending of anything in the clear. It does mean that if the NAS gets hacked, they get access to my Foxsat too. However, they'd need to break in as root to get access to the private keys. The Foxsat is easier to break into.

I agree injecting commands is not a great. I wouldn't do that on a public network.

Fundamentally, the NAS should be an extension to the Foxsat's file system. It is therefore far more logical that the Foxsat is in control of the process. How do you plan to handle unmounting when the NAS drops out? What happens if the Foxsat wasn't responding at the time the NAS booted?
I have written a couple of bash files and placed them inside the foxsat, one to mount, the other to unmount. It appears that unmounting does nothing useful though. If the NAS is unmounted while the foxsat is playing, it seems the foxsat continues to play? I guess that the network is marked as busy so though the command it sent, it actually hasn't dropped the mount. If the network disconnects while NAS is mounted, play freezes, and after a while, a message shows up saying the channel in encrypted. That's fine though.

I didn't do much yesterday besides setting up the SSH and adding two files to the NAS, which SSH into the FOXSAT to call two other files. Idea with that was I can go either (internal or remote) to mount or un-mount. I did try to do it your way to start. I created a third bash file and intended it to be the ping file. Idea is

Ping NAS
if NAS alive
{
if already mounted { exit }
else {mount the nas}
}
else
{
if already mounted { dismount }
else { exit }
}

Unfortunately I got stuck with a stupid bash problem. My "if" kept throwing an error. "No fi" it said. Liar I said. - grrrr.
I can mount (or dismount) the NAS from the NAS now, I haven't set it up to be automatic on startup as yet.

Slow replies, sorry.
 
Does that make me sadistic or masochistic? Maybe a little of both ;)
Yes. I would have you locked up if I were the people you'd inflicted it on. But then you might think that about me :o_O:.
If the NAS is unmounted while the foxsat is playing, it seems the foxsat continues to play?
I guess it's a lazy unmount i.e. it will unmount when the last file using it is closed.
Unfortunately I got stuck with a stupid bash problem.
Bash is not C. As /df always says, shellcheck.net is your friend.
Code:
#!/bin/sh
if true; then
  echo Yes
else
  echo No
fi
 
Yes. I would have you locked up
I'm a good buoy I am, honest guvna 🤥

Bash is not C. As /df always says, had to remove as I'm not allowed to post external links yet, even as a quote is your friend.
#!/bin/sh if true; then echo Yes else echo No fi
I'll look at that site, thanks. I have to stop you at line 1 though as no such directory exists on the Foxsat so I removed it yesterday from the mount and unmount files just to get it to work. There is a sh link to nowhere in /bin. Script seems to default to bash without it, so when I got time, I will use find to look for 'dash'. Think the root of the file system is locked into flash memory so it be somewhere different. There's a lack of bash commands to check what's mounted in the Foxsat so I decided to look for the IP address of the NAS in the mount instead. If it's there, it's mounted, if not, it isn't.

Code:
/bin/mount | grep 192.168.143.12 > /dev/null && r=true || r=false;
echo $r
if ($r); then
echo"hurrah"
else
echo"Boooo!!" ;
fi
exit 0

Below is output from the Foxsat command line.
Code:
Foxsat-HDR~# /mnt/hd4/opt/bash/NASPing.sh
: not foundt/bash/NASPing.sh: /mnt/hd4/opt/bash/NASPing.sh: 1:
false
/mnt/hd4/opt/bash/NASPing.sh: /mnt/hd4/opt/bash/NASPing.sh: 10: Syntax error: end of file unexpected (expecting "fi")
Foxsat-HDR~#
Foxsat-HDR~#

Foxsat-HDR~# /mnt/hd4/opt/bash/NASmount.sh
Foxsat-HDR~#
Foxsat-HDR~# /mnt/hd4/opt/bash/NASPing.sh
: not foundt/bash/NASPing.sh: /mnt/hd4/opt/bash/NASPing.sh: 1:
true
/mnt/hd4/opt/bash/NASPing.sh: /mnt/hd4/opt/bash/NASPing.sh: 10: Syntax error: end of file unexpected (expecting "fi")
Foxsat-HDR~#
Foxsat-HDR~#

Oh darn it, I've run out of time. Got to to DASH ... get it ;)
 
I have to stop you at line 1 though as no such directory exists on the Foxsat so I removed it yesterday from the mount and unmount files just to get it to work. There is a sh link to nowhere in /bin.
It was meant as a generic Linux example, not a specific Foxsat thing. Where does /bin/sh point to then? I'd have thought almost every Linux on the planet had that valid, but I no longer have access to a Foxsat to check.
The rest of your stuff seems to suffer from typos or something (as well as residual C style coding).
 
Where does /bin/sh point to then?
Foxsat-HDR~# ls -l /bin/sh
lrwxrwxrwx 1 root root 7 Feb 9 2014 /bin/sh -> busybox

Dash on the Pi is 130k, on the PC it's 123k. busybox on the Foxsat is 656k, but all 53 links in /bin point to busybox.
The rest of your stuff seems to suffer from typos or something (as well as residual C style coding).
A bit harsh :cry:. I tried lots of hopeless things like changing the square brackets to round, inserting ; in places ; shouldn't go. I just can't get bash on the foxsat to deal with any 'if' statement. It either complains 'expecting then' or "expecting fi'. I will have another look on Sunday.

Formatting Complaint : I appreciate that bash can all go on one line (mostly), but for accurate error messages, it is far better to split it up into multiple lines. If someone would like to send a bit of simple code to test the if statement, I'll happily test it. The below doesn't work. Expecting "then"!
Code:
a="Wednesday"
if [ $a = "Wednesday" ] ; then
echo "It's Wednesday"
else
echo "it's not Wednesday"
fi
 
I have to stop you at line 1 though as no such directory exists on the Foxsat so I removed it
There is a sh link to nowhere in /bin
all 53 links in /bin point to busybox
Foxsat-HDR~# ls -l /bin/sh
lrwxrwxrwx 1 root root 7 Feb 9 2014 /bin/sh -> busybox

Anyone else confused?

It is correct that all links in /bin point to busybox. I have tested your script above (literally cut and pasted from post #26 and with the shebang added back in) and it works just fine on the Foxsat:

Code:
Foxsat-HDR/opt# ls /bin
[          chmod      df         find       hexdump    ln         mount      ping       run-parts  su         umount
[[         chown      dmesg      free       hostname   login      mv         ps         sed        tar        unzip
ash        cp         echo       grep       id         ls         nice       pwd        seq        test       wget
busybox    date       egrep      gunzip     kill       mkdir      nslookup   rm         sh         time       zcat
cat        dd         fgrep      gzip       killall    mknod      passwd     rmdir      sleep      touch
Foxsat-HDR/opt#
Foxsat-HDR/opt#
Foxsat-HDR/opt# cat ./test.sh
#!/bin/sh
a="Wednesday"
if [ $a = "Wednesday" ] ; then
echo "It's Wednesday"
else
echo "it's not Wednesday"
fi

Foxsat-HDR/opt#
Foxsat-HDR/opt#
Foxsat-HDR/opt# ./test.sh
It's Wednesday

Just for the sake of it, I also took your script from post #24 and, after adding back the shebang and adding a space between the two "echo" commands and the double quote, it works fine:

Code:
Foxsat-HDR/opt# cat ./test2.sh
#!/bin/sh
/bin/mount | grep 192.168.143.12 > /dev/null && r=true || r=false;
echo $r
if ($r); then
echo "hurrah"
else
echo "Boooo!!"
fi
exit 0

Foxsat-HDR/opt#
Foxsat-HDR/opt#
Foxsat-HDR/opt# ./test2.sh
false
Boooo!!
Foxsat-HDR/opt#

My guess is that this could be a CRLF thing. I created and edited the two scripts above directly on the Foxsat using vi (took me back FAR too many years!). Are you creating/editing your scripts on Windows by any chance, and then copying them to the Foxsat to run? Have a Google of "how does bash handle crlf".
 
Last edited:
  • Like
Reactions: TW8
My guess is that this could be a CRLF thing.
I was about to suggest that.

Are you creating/editing your scripts on Windows by any chance
Probably, using Notepad! @TW8: download Notepad++ and set "Unix line endings" in preferences (or whatever the setting is – you need it to output LF only). Alternatively, create your scripts directly on the Foxsat with a command-line editor (vi, nano).

Or you could carry on as you are and run the resulting script through a CR stripper (dos2unix).
 
Last edited:
  • Like
Reactions: TW8
I just can't get bash on the foxsat to deal with any 'if' statement.
Bash on the Foxsat works like bash on any other system. You just don't appear to know how to use it properly. I would suggest reading up on the correct syntax rather than guessing.
It either complains 'expecting then' or "expecting fi'.
As others have said, I expect you are not using Unix line endings. I gave you a sample in #23. If you can't get that to work then you are doing something fundamentally wrong which needs fixing before moving on.
 
I have to stop you at line 1 though as no such directory exists on the Foxsat so I removed it yesterday from the mount and unmount files just to get it to work. There is a sh link to nowhere in /bin.
So none of that is true. I might leave you to it.
 
My guess is that this could be a CRLF thing.
You were absolutely correct about CR/LF. When I set the file to unix mode, it runs perfectly. Thank you so much. Script pings works from the command line, not tried it from command line yet.
I was about to suggest that.
Thank you too. I appreciate your help and ideas on this too.


Code:
#!/bin/sh

ping -c 1 192.168.143.12 > /dev/null && conx=1 || conx=0
/bin/mount | grep 192.168.143.12 > /dev/null && mounted=1 || mounted=0;

if [ $conx = "1" ] && [ $mounted = "0"  ]  ; then
mount -t cifs -o user=****,password=**** "//192.168.143.12/Video" /media/sdb1
fi

if [ $conx = "0" ] && [ $mounted = "1"  ]  ; then
umount -l /media/sdb1
fi

Regarding me posting the /bin/sh link pointed nowhere, I was wrong. I should have gone to the command line first.
 
Back
Top