0

I have two different script 1st one is

sar -u -s 11:00:00 -e 11:10:59 | grep Average: | awk '{printf($8)}'

2nd one will show the time which is 60 min old

date -d '60 minute ago' "+%H:%M:%S"

I want to use 2nd sctipt in 1st script (without creating any .sh file) Below code is not working

sar -u -s `date -d '60 minute ago' "%H:%M:%S"` -e 11:10:59 | grep Average: | awk '{printf($8)}'
4
  • 1
    What exactly does is not working mean? Commented Aug 25, 2021 at 6:48
  • If you would have tried running the command you wrote, the shell would tell you what's wrong. argument must be a format string beginning with '+'. Give it a try. Commented Aug 25, 2021 at 6:55
  • I want to use the result of a 2nd command as input for a 1st command @user1934428 Commented Aug 25, 2021 at 9:58
  • Your "1st command" is a sar command. While I have never used sar, it does not, AFIK, process standard input. Please specify in your question (not in a comment), what you understand under input for the 1st command. Perhaps you mean "you want to use the standard output of the 2nd command as a parametre for the 1st command"? But this is what you already did in the code you posted; you only forgot to copy over the + sign. BTW, using $(....) instead of backquotes is more idiomatic for doing command substitution. Commented Aug 25, 2021 at 11:10

1 Answer 1

1

When I try this, your second command seems not to work, it should be:

date -d '60 minute ago' "+%H:%M:%S"

(Mind the "+" at the beginning of your format string)

When I use this, using $(...) instead of the accent graves, for readability, everything seems to be working fine:

echo $(date -d '60 minute ago' "+%H:%M:%S")
Sign up to request clarification or add additional context in comments.

2 Comments

@ceving: not useless: I demonstrated, using echo, how to use the result of a first command as input for a second command.
you are right. it was the about that + sign sar -u -s date -d '60 minute ago' "+%H:%M:%S"` -e 11:10:59 | grep Average: | awk '{printf($8)}'`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.