I get the current time from the system with datetime and save it as a string (timenow), but there is some difference in behavior when I send it for installation on linux via sshclient_exec_command.
Below is my code:
timenow = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
command = 'date -s %s' %timenow
stdin, stdout, stderr = self._sshclient.exec_command(command, timeout=10)
try:
command = 'date +"%Y-%m-%d %H:%M:%S"'
stdin, stdout, stderr = self._sshclient.exec_command(command, timeout=10)
ip_time_now = stdout.read().decode(encoding='UTF-8').rstrip('\n')
self.logger.debug(" ip=%s timenow=%s ip_time_now=%s",ip, timenow,ip_time_now)
Output
timenow=2016-09-07 20:15:26 ip_time_now=2016-09-07 21:06:24
Both timenow and ip_time_now should be the same of operations
Here, if I replace the timenow string with
timenow = datetime.datetime.utcnow().strftime("%H:%M:%S")
setting the year and month
Output
timenow=20:25:49 ip_time_now=2016-09-07 20:25:50
Note. An exception is not output when executing commands
What could be possible for strftime syntax?
source
share