Find the answer to your Linux question:
Results 1 to 3 of 3
I am brand new to Linux. And trying to learn Python at the same time. I have written some python code for a client to query a server for the ...
  1. #1
    Just Joined! naCougar's Avatar
    Join Date
    Sep 2008
    Posts
    2

    Permission to set the Clock in Debian Linux

    I am brand new to Linux. And trying to learn Python at the same time.

    I have written some python code for a client to query a server for the time and set the local clock. I am trying to run the code on Debian Linux and am having permission issues.

    Here is a snippet of the program:
    t = strftime('%H:'+'%M:'+'%S' , the_time)
    system("date -s" + t)

    I was able to get the clock to change the time, after changing the file’s permission to root.
    Is there a better way to do this?

    My second issue is using crontab to run the code every half hour. I used the GUI Kcron and it set up to run every half hour. It will not run, most likely due to more permission issues.
    Any suggestions are greatly appreciated.
    Thanks

  2. #2
    Linux Guru
    Join Date
    Nov 2007
    Posts
    1,695
    Changing the time on a system is a powerful command, so you need root access (by default) to do it.

    You can:
    A) Be logged in (or su) as root
    B) Enable a regular user to run the command via sudo
    C) Enable the SetUID bit on the date command (not desirable)

    There is a Linux command/package called ntpdate. You can install it with:

    Code:
    apt-get install ntpdate
    To update your time against an NTP server:

    Code:
    /usr/sbin/ntpdate pool.ntp.org

  3. #3
    Just Joined! naCougar's Avatar
    Join Date
    Sep 2008
    Posts
    2

    more help

    Unfortunately I can't use ntpdate.

    I have tried the SUDO option. I changed my date command to:
    system("sudo date-s" + t)

    I have changed ownership of my set_client.py code file to root.

    Now I need to set it up to run every 30 minutes using cron/crontab or whatever.

    There are so many folders with the word cron in them I don't know which to edit. I know how to use nano to edit the cron files.
    I would like the program to run every 30 minutes and be initiated also upon reboot.

    I edited /etc/crontabs using nano and inserted this line:
    */30 * * * * root /home/kevin/set_client.py

    This is not working for me can anyone tell me which cron location to use and what the command line should look like.
    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...