Script help. Is it possible to login as a user from a script?

I've got a script that runs when a user logs in (Login=modem, which executes script modem which restarts PPP), is it possible in that script after it restarts the PPP to actually login as another user?  Basically, the user has to log out and log back in as 'modem' and then log back into their account, I'd like for them to only have to log out of their account and log in as modem which will restart the modem and log them back in to their own account.
gofferAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gofferAuthor Commented:
Also, is there a way in a script to run certain commands as root, but run other commands without root permissions.  I've got some other scripts and programs that root can't run (part of a POS), but I need root permissions to restart the PPP.  
TintinCommented:
What you should do is use sudo to control access to various privileged commands that you want specified users to run.

In this instance, you should give sudo permissions for the user to run the modem script to restart PPP, so that they don't have to login as another user.

To set this up, as the root user, type in

visudo

and add the following entry:

user ALL=/path/to/modem-script

Where 'user' is the user name you want to run the modem script.  It also assumes that the modem script needs to be run as root.  If this is not the case, then specify the user like

user ALL=(modem) /path/to/modem-script

Then the user simply types in

sudo /path/to/modem-script

or it needs to run as a non-root user

sudo -u modem /oath/to/modem-script

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gofferAuthor Commented:
Do I need to add both the user ALL=/path/to/modem-script AND user ALL=(modem) /path/to/modem-script?  Or is the second if I only want user modem to be able to use sudo /path/to/modem-script?
TintinCommented:
You have one or the other.

If the modem-script needs to run a a non-root user, say 'modem', then use the second configuration.
gofferAuthor Commented:
Works great, thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.