Concatenate “date” and “uptime” command in linux/adb

huangapple go评论120阅读模式
英文:

Concatenate "date" and "uptime" command in linux/adb

问题

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

英文:

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

答案1

得分: 0

这是您需要的部分:

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

请注意引号和 printf 的用法以连接输出。

英文:

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.

huangapple
  • 本文由 发表于 2023年2月13日 23:08:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75437696.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定