[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: run command as root within script



> Is there a way within a bash script to temporarily
> su to the root user, then run some commands,
> then go back to the original user?

Yes - learn to use sudo

>From the man page:

DESCRIPTION
       sudo allows a permitted user to execute a command as the superuser or
       another user, as specified in the sudoers file.

So for example you might have as part of your nightly maintance:

sudo apt-get update ; sudo apt-get upgrade -d

Put the script in your crontab (as opposed to roots crontab), and every
night your machine will connect to the net, update the apt cache, check to
see if you need any updates and download them ready for your approval and
installation.

> Or can you temporarily (within a script), assign
> the current user to have more rights, then take
> away those rights?

That's about as temporary as you're gonna get.

> bash scripting is fairly new to me.
>
> Thanks,
> -Rick

Good luck




Reply to: