Script wont work at startup

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> General Questions
Author Message
portsup
DD-WRT User


Joined: 20 Oct 2018
Posts: 154

PostPosted: Sun Oct 17, 2021 23:31    Post subject: Script wont work at startup Reply with quote
I have a script portforward.sh that works fine otherwise. I have it on my /opt drive. I am running it from the startup script with this code

Code:
sleep 25
transmissiond --config-dir /opt/transmission/config
sleep 5
/opt/wireguard/portforward.sh


When it runs from there it malfunctions but I can't see anything in the log. First how do I get it's errors visible in the log? and second any idea what could be wrong. I do know the script is running but the files it writes variables to are all blank. Here is the code https://pastebin.com/GJafHTY1


Code:
#!/bin/sh
#sets script dir as working dir
cd "$(dirname "$0")"
PIA_CERT="ca.rsa.4096.crt"
PIA_TOKEN=$(cat PIA_TOKEN)
PIA_SERVER_IP=$(cat PIA_SERVER_IP)
PIA_WG_CN=$(cat PIA_WG_CN)
 
PF_SIG="$(curl --interface oet1 --CAcert $PIA_CERT --get --silent --show-error --retry 5 --retry-delay 1 --max-time 2 --data-urlencode token=$PIA_TOKEN --resolve $PIA_WG_CN:19999:$PIA_SERVER_IP https://$PIA_WG_CN:19999/getSignature)"
 
echo $PF_SIG
#various files are generated which are needed to run portforwardbind.sh
echo $PF_SIG>PF_SIG
PF_PAYLOAD_RAW="$(echo $PF_SIG | jq -r '.payload')"
echo $PF_PAYLOAD_RAW>PF_PAYLOAD_RAW
PF_PAYLOAD="$(echo $PF_PAYLOAD_RAW | base64 -d )"
echo $PF_PAYLOAD
#unworking expiry function
#PF_TOKEN_EXPIRY_RAW=$(echo $PF_PAYLOAD | jq -r .expires_at)
#PF_TOKEN_EXPIRY=$(date --date="$PF_TOKEN_EXPIRY_RAW" +%s)
PF_GETSIGNATURE=$(echo $PF_SIG | jq -r .signature)
echo $PF_GETSIGNATURE>PF_GETSIGNATURE
#pulls the assigned port
PF_PORT=$(echo $PF_PAYLOAD | jq -r .port)
echo $PF_PORT
echo $PF_PORT>PF_PORT
./portforwardbind.sh
Sponsor
Alozaros
DD-WRT Guru


Joined: 16 Nov 2015
Posts: 4805
Location: UK, London, just across the river..

PostPosted: Mon Oct 18, 2021 4:34    Post subject: Reply with quote
i guess you did make it executable ??

code:
chmod +x script path

and where exactly it should store its stuff in opt?
apart of tmp that doesn't survive reboot and opt that is on usb and survives reboot the other fs is ready only….

_________________
Atheros
TP-Link WR740Nv1 ---DD-WRT 48081 AP,NAT
TP-Link WR1043NDv2 -DD-WRT 47900 AP,NAT,AP Isolation,Ad-Block,Firewall,Local DNS,Forced DNS,DoT,VPN,VLAN
TP-Link WR1043NDv2 -DD-WRT 48081 AP,NAT,Ad-Block,Firewall,Local DNS,Forced DNS,DoT,VPN,VLAN
TP-Link WR1043NDv2 -Gargoyle OS 1.13.0b AP,NAT,QoS,Quotas
Qualcomm-Atheros
Netgear R7800 --DD-WRT 48081 AP,NAT,AD-Block,AP&Net Isolation,VLAN's,Firewall,Local DNS,DoT,Vanilla
Netgear R9000 --DD-WRT 48081 AP,NAT,AD-Block,AP Isolation,Firewall,Local DNS,DoT,2,4Ghz only,Vanilla
Broadcom
Netgear R7000 ---DD-WRT 48081 AP,Wi-Fi OFF,NAT,AD-Block,Firewall,Local DNS,Forced DNS,VLAN's,DoT,VPN
------------------------------------------------------
Stubby for DNS over TLS I DNSCrypt v2 by mac913


Last edited by Alozaros on Mon Oct 18, 2021 7:43; edited 1 time in total
portsup
DD-WRT User


Joined: 20 Oct 2018
Posts: 154

PostPosted: Mon Oct 18, 2021 5:34    Post subject: Reply with quote
no it was the lack of PATH for the binaries jq (and base64 in another script) I use in /opt/bin. Added the line
Code:
export PATH=$PATH:/opt/bin
to fix it. I was trying to get a cron job with another script 'connect.sh' to work and it wouldn't so I searched and found you can output a cron job to a txt file. For this I used after the cron timer
Code:
root /opt/wireguard/connect.sh >> /opt/connectlog.txt 2>&1
. This showed me the error in that txt file. Searching here found that cron and presumable startup don't share the same PATH as telnet. I used
Code:
echo $PATH
to see the cron PATH '/usr/bin:/bin:/sbin:/usr/sbin:/jffs/sbin:/jffs/bin:/jffs/usr/bin:/jffs/usr/sbin' which is quite limited compared to telnet's '/bin:/usr/bin:/sbin:/usr/sbin:/jffs/sbin:/jffs/bin:/jffs/usr/sbin:/jffs/usr/bin:/mmc/sbin:/mmc/bin:/mmc/usr/sbin:/mmc/usr/bin:/opt/sbin:/opt/bin:/opt/usr/sbin:/opt/usr/bin'. I am surprised all those are needed when /opt/bin is where every installed package goes and that the other path doesn't have that added. Kind of a stupid lack of a feature.

Would be nice if the syslog showed the script outputs and errors too.
Alozaros
DD-WRT Guru


Joined: 16 Nov 2015
Posts: 4805
Location: UK, London, just across the river..

PostPosted: Mon Oct 18, 2021 7:55    Post subject: Reply with quote
hmm use a logger -t or logger -p ...
_________________
Atheros
TP-Link WR740Nv1 ---DD-WRT 48081 AP,NAT
TP-Link WR1043NDv2 -DD-WRT 47900 AP,NAT,AP Isolation,Ad-Block,Firewall,Local DNS,Forced DNS,DoT,VPN,VLAN
TP-Link WR1043NDv2 -DD-WRT 48081 AP,NAT,Ad-Block,Firewall,Local DNS,Forced DNS,DoT,VPN,VLAN
TP-Link WR1043NDv2 -Gargoyle OS 1.13.0b AP,NAT,QoS,Quotas
Qualcomm-Atheros
Netgear R7800 --DD-WRT 48081 AP,NAT,AD-Block,AP&Net Isolation,VLAN's,Firewall,Local DNS,DoT,Vanilla
Netgear R9000 --DD-WRT 48081 AP,NAT,AD-Block,AP Isolation,Firewall,Local DNS,DoT,2,4Ghz only,Vanilla
Broadcom
Netgear R7000 ---DD-WRT 48081 AP,Wi-Fi OFF,NAT,AD-Block,Firewall,Local DNS,Forced DNS,VLAN's,DoT,VPN
------------------------------------------------------
Stubby for DNS over TLS I DNSCrypt v2 by mac913
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum