[Solved] Dhcp hotplug script is not working

I put that script:

logger "Check"
cat /tmp/dhcp.leases | awk '{print $2" "$4}' | ssh "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.

+ logger 'Check'
+ cat /tmp/dhcp.leases
+ awk+ ssh '{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 '{print $2" "$4}' 'cat > /tmp/dhcp.leases'
should be

+ awk '{print $2" "$4}'
+ ssh  'cat > /tmp/dhcp.leases'

Is your output correct or copy-paste error?

1 Like
+ logger 'Check'
+ cat /tmp/dhcp.leases
+ awk+ ssh '{print $2" "$4}' 'cat > /tmp/dhcp.leases'

This is exactly the ouput.

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 as user root (ssh root@ Is that what you have in mind?

What do you mean?

How to you connect with PuTTY, what user do use there. How many users are there on

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 "cat > /tmp/dhcp.leases"

on putty, yes

No on the OpenWrt router, is what I meant.

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?

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@

Quite - a use case might help.

it does'nt work either, but works with PuTTY