0

I have some problems with ntpd sync on servers. Unless we resolve this issue I have written script to set date on servers manually for those who are not in sync.

For this I have taken one reference machine and I am catching current date of that machine and trying to set it on all other machines.

I'm using following command in script

ssh -i /mnt/keys/g.pem -o StrictHostKeyChecking=no root@$IP 'date --set="$ref_date"'

but when command runs it set wrong date.

e.g ref_date=Sat Sep 24 06:52:17 UTC 2016

when I echo above command it shows following line

ssh -i /mnt/keys/g.pem -o StrictHostKeyChecking=no root@xx.xx.xx.xx 'date --set="Sat Sep 24 06:52:17 UTC 2016"'

but when same command actually runs it gives following output

ssh -i /mnt/keys/g.pem -o StrictHostKeyChecking=no root@xx.xx.xx.xx 'date --set="Sat Sep 24 06:52:17 UTC 2016"'

Sat Sep 24 00:00:00 UTC 2016

Note: I have replaced $IP with xx.xx.xx.xx in above outputs.

Kindly provide solution to this.

innervoice
  • 120
  • 2
  • 13
  • What do you get if you try `'date --date="Sat Sep 24 06:52:17 UTC 2016"'` ? –  Sep 24 '16 at 07:47

1 Answers1

2
ssh -i /mnt/keys/g.pem -o StrictHostKeyChecking=no root@$IP "date --set=\"$ref_date\""

See: Difference between single and double quotes in Bash

Community
  • 1
  • 1
Cyrus
  • 84,225
  • 14
  • 89
  • 153