1

What is the option for date to give output in a format acceptable to date --set ?

I'm trying to remotely set the date, using the current computer clock of my workstation.

ssh user@host sudo date --set="`date`"

and

ssh user@host sudo date --set="`date -R`"

both give "extra operand" and "invalid option" errors.

Yes, I know I can type --set="YYYY-MM-DD HH:mm:ss", but the computer should be able to do that for me.

1 Answer 1

1

date does accept its output, if quoted. Sending quotes through ssh needs escaping.

This works:

ssh user@host sudo date --set="\"`date -R`\""

Some systems might not accept the above, but will accept

ssh user@host sudo date -u --set="\"`date -u +"%Y.%m.%d-%T"`\""
1
  • @slm: I think the quotes will still be eaten by my workstation shell and not go through ssh
    – Ben Voigt
    Commented Nov 23, 2013 at 2:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .