shell - Go into sudo user, run couple of commands, go back to normal user in Python script -


the problem i've run want temporarily sudo user, run couple of commands, , go normal user , run commands in mode.

you can find script i'm gonna use in here: https://github.com/greduan/dotfiles/blob/master/scripts/symlinks.py

basically, when i'm installing scripts under /bin folder of dotfiles need sudo access in order make symlink folder. can find part of script under last statement in code.

however, since depend on commands use current user guideline stuff, can't run entire script sudo. last time tried got lot of errors folder not existing.

thanks can provide.

if don't mind installing external dependency, sh module makes pretty simple:

import sh  sh.cp('foo.txt', 'bar.txt')  sh.sudo:     sh.cp('foo2.txt', 'bar2.txt') 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -