I need to use this for a Samsung Tablet.
Usually if the device is switched-off and the USB cable is being connected the display will wake up for some seconds showing
These answers led me to my solution. I'm using this on a Samsung Galaxy Tab S. For other tablets, the path to the system mount will be different. To find it, use this command in an adb shell.
cat /proc/mounts | grep system
One problem I came across was the tablet booting into recovery mode after I changed the lpm file, but that's because I mv'd the old one and created a new lpm file and didn't set the correct permissions and ownership. Using cp instead fixed this. My one-liner to set this up on a tablet is:
mount -o remount,rw /dev/block/platform/dw_mmc.0/by-name/SYSTEM /system && cp /system/bin/lpm /system/bin/lpm_orig && echo "#!/system/bin/sh\n/system/bin/reboot" > /system/bin/lpm