-1

I need to create a script which I need to concatenate the result of "date" with "uptime" for example

Date:

date '+%a, %b %d %T %z %Y'
Mon Feb 13 15:04:05 GMT 2023

And when I run uptime into a terminal emulator appears the following:

15:04:34 up 2 days, 20:14,  0 users,  load average: 1.95, 1.97, 1.81

Which I need to expect that those command is displayed into a single line:

Mon Feb 13 15:04:05 GMT 2023 15:04:34 up 2 days, 20:14,  0 users,  load average: 1.95, 1.97, 1.81

I need perform this script to check the uptime with the date of an Android device using shell

Currently, I have this command but the uptime doesnt appears the "load average data"

adb -s 10.0.0.2:5555 shell ""while true;do date '+%a, %b %d %T %Z %Y $(uptime)';sleep 1;done""
Mon, Feb 13 15:07:44 GMT 2023  12:07:44 up 40 days, 18:33,  0 users,  load average: 0.00, 0.00, 0.00

So "Load average appears" 0.00

any helps pls

javier
  • 11
  • 5
  • Did you run the `uptime` command that displays the expected values on the same Android system? Please [edit] your question to answer. (When I run `uptime` in a terminal emulator on my Android phone, there is no load average output at all.) – Bodo Feb 13 '23 at 15:19
  • Thanks for the feedback, edited. Yes when I run uptime inside terminal emulator, appears coorectly the Loads average – javier Feb 13 '23 at 15:30
  • Does `uptime` alone work as expected in `adb`? – Bodo Feb 13 '23 at 19:04

1 Answers1

0

This is what you need

adb -s 10.0.0.2:5555 shell 'while true; do printf "%s %s\n" "$(date)" "$(uptime)"; sleep 1; done'

notice the use of quotes and printf to join the output.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134