Thread: popen and vim

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Posts
    3
    Rep Power
    0

    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!

    Haora
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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,

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Posts
    3
    Rep Power
    0
    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!!!
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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,

    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Posts
    3
    Rep Power
    0
    Thanks for your help...., I'll probably just ask for a password....

    Thanks again!

IMN logo majestic logo threadwatch logo seochat tools logo