LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-24-2004, 07:54 AM   #1
lapthorn
Member
 
Registered: Jul 2003
Location: Reading
Distribution: Red Hat
Posts: 89

Rep: Reputation: 16
Using su <username> in Script


I have an application that runs in the evenings that uses 'ntpdate' to sync the machines clock.

My problem is testing 'ntpdate' as a non root user using sudo. The script I am running is executed as root. I want the script to check that everything is working by running 'ntpdate' as a non root user.

i have tried the following:

su dbs1;ntpdate -b <mytimeserver>;exit

but when the script executes it gives me a shell prompt and doesn't continue until I type exit.

Is there anyway I can execute commands in a script as another user without using su, what I need is a reverse sudo command??

Or does anyone know the correct syntax???
 
Old 02-24-2004, 09:38 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
I would do something like
sudo -u dbs1 ntpdate -b <mytimeserver>
 
Old 02-24-2004, 09:43 AM   #3
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
yeah, su is simply a switch user command sudo executes a command as another user
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why "bash-2.05b$" in Terminal instead of "username@localhost username" jayelitumbiolo Linux - General 9 10-04-2009 03:16 AM
bash script that uses username/password paul_mat Linux - Software 2 10-25-2005 10:44 PM
Cannot login without Username, help! utcltjay Linux - General 1 09-06-2005 05:18 PM
CGI script: username specific hamish Linux - Software 1 01-17-2005 08:00 AM
useradd: invalid username username$ engyeow Fedora 5 12-05-2004 04:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration