eR2022
March 16, 2023, 8:10pm
1
Hi,
I put that script:
logger "Check"
cat /tmp/dhcp.leases | awk '{print $2" "$4}' | ssh 192.168.1.2 "cat > /tmp/dhcp.leases"
in /etc/hotplug.d/dhcp
I see the syslog message, but the ssh is not working.
Same ssh code in PuTTy working great.
And I have ssh keys saved.
What could be the problem?
do you mean if you execute the whole command in cli ?
what's the error message in syslog?
is the script executed as root ?
1 Like
Run your script manually as sh -x {scriptname}
and check the output for errors.
eR2022
March 16, 2023, 8:25pm
4
+ logger 'Check'
+ cat /tmp/dhcp.leases
+ awk+ ssh 192.168.1.2 '{print $2" "$4}' 'cat > /tmp/dhcp.leases'
I'm not sure if I run it as root, How to check?
do a touch /tmp/somefile.ext
in the script, see who the owner is, afterwards.
The third line is strange
+ awk+ ssh 192.168.1.2 '{print $2" "$4}' 'cat > /tmp/dhcp.leases'
should be
+ awk '{print $2" "$4}'
+ ssh 192.168.1.2 'cat > /tmp/dhcp.leases'
Is your output correct or copy-paste error?
1 Like
eR2022
March 16, 2023, 8:44pm
7
+ logger 'Check'
+ cat /tmp/dhcp.leases
+ awk+ ssh 192.168.1.2 '{print $2" "$4}' 'cat > /tmp/dhcp.leases'
This is exactly the ouput.
Permissions:
The script will run as root, that is then also the user implicit used for the ssh. Meaning that it will try to login to 192.168.1.2 as user root (ssh root@192.168.1.2
). Is that what you have in mind?
How to you connect with PuTTY, what user do use there. How many users are there on 192.168.1.2?
eR2022
March 16, 2023, 8:53pm
11
root user on PuTTY
no other users
Ok, sounds right then, does it work if you manually just run this line:
cat /tmp/dhcp.leases | awk '{print $2" "$4}' | ssh 192.168.1.2 "cat > /tmp/dhcp.leases"
No on the OpenWrt router, is what I meant.
eR2022
March 16, 2023, 8:58pm
15
How to run on OpenWrt without ssh? luci-commands?
You connect with PuTTY to your OpenWrt router and there is ssh
available. Or am I not understanding you correct?
Or have disabled SSH in LuCI?
eR2022
March 16, 2023, 9:02pm
17
im lost brother, could we keep talking in DM?
Awkward looking command - you could use scp
instead, although you'd need to create a temporary file using the awk expression first or do the post processing on whatever server you're sending it to.
You'd transfer the file using scp something like this
scp /tmp/dhcp.leases root@192.168.1.2:/tmp/dhcp.leases
2 Likes
dl12345:
Awkward looking command
Quite - a use case might help.
eR2022
March 16, 2023, 9:40pm
20
it does'nt work either, but works with PuTTY