Hello community,
I wrote a script, which edits a file and copies it into another folder.
If I execute it myself it works just fine and does its work but as long as Node-Red is executing it with the exec node, the files content isnt changing. I dont get any error messages etc. (not even something about permissions).
I want the user to change the network settings in the dashboard, easily with a form. But for debugging I'm just using some random parameters:
Below you can see the script so you get a point what im trying to do.
#!/bin/bash
##############################################################################
mask2cidr() {
nbits=0
IFS=.
for dec in $1 ; do
case $dec in
255) let nbits+=8;;
254) let nbits+=7;;
252) let nbits+=6;;
248) let nbits+=5;;
240) let nbits+=4;;
224) let nbits+=3;;
192) let nbits+=2;;
128) let nbits+=1;;
0);;
*) echo "Error: $dec ist not recognised"; exit 1
esac
done
echo "$nbits"
}
##############################################################################
ip=$1
netmask=$2
gateway=$3
numbits=$(mask2cidr $netmask)
cat << EOF > dhcpcd.conf
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.
# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel
# Inform the DHCP server of our hostname for DDNS.
hostname
# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid
# Persist interface configuration when dhcpcd exits.
persistent
# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit
# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu
# Most distributions have NTP support.
#option ntp_servers
# A ServerID is required by RFC2131.
require dhcp_server_identifier
# Generate SLAAC address using the Hardware Address of the interface
#slaac hwaddr
# OR generate Stable Private IPv6 Addresses based from the DUID
slaac private
#auto eth0
interface eth0
static ip_address=${ip}/${numbits}
static routers=$gateway
# Example static IP configuration:
#interface eth0
#inform 10.207.40.10/24
EOF
sudo rm /etc/dhcpcd.conf
sudo cp /home/pi/NetConfig/dhcpcd.conf /etc/
exit 0
Kind regards
Justin