2

I'm on Kali Linux with VERSION_ID="2019.3"


uname -a
Linux kali 4.19.0-kali5-amd64 #1 SMP Debian 4.19.37-6kali1 (2019-07-22) x86_64 GNU/LINUX


Trying to execute adjust_timezone.sh placed in /usr/local/startup_scripts/

#!/bin/sh
echo "Adjusting timezone...";   
ntpdate in.pool.ntp.org;  

The output of which ntpdate

/usr/sbin/ntpdate

I tried using the full path in the script too, no success.


The content of /etc/crontab

SHELL=/bin/sh  
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
@reboot /usr/local/startup_scripts/adjust_timezone.sh

Added the same using crontab -e too

@reboot /usr/local/startup_scripts/adjust_timezone.sh  

I tried using @reboot : /usr/local/startup_scripts/adjust_timezone.sh too with no success.
I modified the script adding 2>&1 >> log.txt but the log is empty, i think the script is never executing.

Where I'm wrong? Any advice?


EDIT
As suggested the logging format was wrong, i changed it in >> /log.txt 2>&1 and here's the result :

/usr/local/startup_scripts/adjust_timezone.sh: 3: ntpdate: not found
Error resolving in.pool.ntp.org: Name or service not known (-2)
20 Aug 15:14:37 ntpdate[612]: Can't find host in.pool.ntp.org: Name or service not known (-2)
20 Aug 15:14:37 ntpdate[612]: no servers can be used, exiting
  • What happens if you run /usr/sbin/ntpdate in.pool.ntp.org directly? Same question, but for /usr/local/startup_scripts/adjust_timezone.sh? – roaima Aug 20 at 16:42
  • 3
    Your 2>&1 >>log.txt is wrong. Try >>/tmp/log.txt 2>&1 (the order is important). – roaima Aug 20 at 16:44
  • Is the script executable? – Kusalananda Aug 20 at 16:59
  • Running /usr/sbin/ntpdate in.pool.ntp.org i get the desired behavior, same result adding /bin/sh before. Yes you're right the log format is incorrect, and yes I made the script executable using chmod +x ... – Roberto Manfreda Aug 20 at 17:10
  • 2
    Ah. Your ntpdate is running before your network's up. – roaima Aug 20 at 17:24
6

Your ntpdate is running before the network is up and functional.

A better solution might be to use the systemd time synchronisation module rather than creating your own. Or install ntpd and let it manage your system's time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.