June 24th, 2005, 12:14 PM
popen and vim
Hi everybody..., I'm new here, and I have a problem when using popen....
The thing is..., I want my script to edit the crontab, and I do this:
f = popen("crontab -e","w");
but I get this error:
Warning: input is not from a terminal
What can I do to edit that file???
Thanks in advance!
June 24th, 2005, 02:55 PM
Python is superb at handling string manipulation, I would suggest that you open the crontab file like you would any other file (make a copy first so you can test your program without damaging the original) and edit it from Python .
Since the crontab file is divided into columns it would best be represented as a list of lists IMO. Read the file into memory and use split() to break it up and you should be away. You can then add new entries, remove old ones and or edit existing entries from within Python .
If you would like an example of this I would be happy to write one for you that you could shape to meet your requirements.
Hope this helps,
June 24th, 2005, 03:31 PM
Yes, I guess I will have to do that..., the only problem with that, is that my cron file, is on a directory, only accesible by the root, so, I have to execute the program like this : "sudo program.py"
Is there any way arround it??
Thanks for the replay!!!
June 24th, 2005, 04:03 PM
An alternative would be to copy the current crontab, make any changes then move the file after as root. Other than that I'm sorry but *nix isn't going to budge on the issue, which is really a good thing.
You could write a shell script to wrap up the sudo call if you'd like, but you'd still have to enter the password unless you edit your sudoers file. Ask in the *nix forums for more help with this .
Hope this helps,
June 27th, 2005, 08:09 AM
Thanks for your help...., I'll probably just ask for a password....