LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-23-2008, 11:08 PM   #1
naCougar
LQ Newbie
 
Registered: Sep 2008
Posts: 3

Rep: Reputation: 0
Unhappy Permission to set the Clock in Debian Linux


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
 
Old 09-24-2008, 12:10 AM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
Why not use ntpdate? Do you need to reinvent the wheel?

Setting the time in Unix/Linux requires administrative permission. You can use sudo and setup a proper sudoers configuration to allow your program's user to set the clock.
 
Old 09-24-2008, 12:50 PM   #3
racracracrac
Member
 
Registered: Sep 2008
Posts: 44

Rep: Reputation: 15
You can also change the permissions on the script to be setuid and set the owner to root. Of course, its a bad idea to do this for scripts... actually its a bad idea for nearly anything.

(link removed)

Last edited by Mara; 10-12-2008 at 03:53 PM. Reason: link removed, as it has nothing to do with this thread
 
Old 09-24-2008, 02:05 PM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
Shell script setuid is a security risk under Linux and is not allowed.
 
Old 09-24-2008, 05:06 PM   #5
naCougar
LQ Newbie
 
Registered: Sep 2008
Posts: 3

Original Poster
Rep: Reputation: 0
still not there

Quote:
Originally Posted by Mr. C. View Post
Why not use ntpdate? Do you need to reinvent the wheel?

Setting the time in Unix/Linux requires administrative permission. You can use sudo and setup a proper sudoers configuration to allow your program's user to set the clock.
Thanks for your advice

I would like to try 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!
 
Old 09-24-2008, 05:37 PM   #6
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
You don't want to set your set_client.py code setuid root. What you want is to create an entry in /etc/sudoers that allows the running user to run the "date ..." command with the exact args you use. See the Examples in man sudoers.

You should also use full paths to your commands in your script. For example "sudo /bin/date ..."
 
Old 09-25-2008, 09:49 AM   #7
naCougar
LQ Newbie
 
Registered: Sep 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Mr. C. View Post
See the Examples in man sudoers.

You should also use full paths to your commands in your script. For example "sudo /bin/date ..."
Thanks for your help. I have never used Unix/Linux or Python. I am just now learning the directory structures and locations of different types of files.
!

I finally discoverd my other issue. When my sudo was running date -s, it was prompting for a password. I had to use Visudo to issue a nopasswd command.
Now I am a happy camper. I found some nice info athttp://www.linuxhomenetworking.com/w...Users_and_Sudo

Last edited by naCougar; 09-25-2008 at 09:55 AM. Reason: added link
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Failed to set system clock to hardware clock jrtayloriv Linux - Newbie 2 09-25-2008 07:06 AM
Linux OS Clock/Timezone shows the clock off by 6 hours between OS's JBailey742 Linux - Software 9 04-06-2006 11:40 PM
How to set the clock 357mag Mandriva 4 03-07-2005 03:08 AM
My clock won't set! johnnyLongside Linux - General 1 03-19-2004 03:00 AM
how do i set my clock in linux? philfighter Linux - General 9 08-22-2001 06:11 PM


All times are GMT -5. The time now is 09:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration