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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -