2

So i have a ash script that send command to device via telnet
The command look like this.

echo 'dofile("lcdprint.lua").lcdprint("date")' | telnet 192.168.1.23 23 

I want the output date like this

Tue Jul 12 17:10:51 WIB 2016

But instead of above output, the code run unexpected with this result

date

How do i send the correct command? The output should contain date value, not 'date' string.
Thankyou :)

mklement0
  • 382,024
  • 64
  • 607
  • 775

1 Answers1

3

If you want to incorporate the output from locally executing the date utility, before sending the command string to the target machine, use $(...), Bash's command substitution:

echo "dofile('lcdprint.lua').lcdprint('$(date)')" | telnet 192.168.1.23 23

Note how the overall string is double-quoted to ensure that $(...) is expanded.

If you want to run date on the target machine, use Lua's os.execute() to run a shell command:

echo 'dofile("lcdprint.lua").lcdprint(os.execute("date"))' | telnet 192.168.1.23 23

Note how the overall string is single-quoted, because no interpretation by Bash is needed in this case, and using single quotes ensures that the string is passed as-is.

mklement0
  • 382,024
  • 64
  • 607
  • 775