LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-26-2009, 06:49 AM   #1
ijf99
LQ Newbie
 
Registered: Dec 2008
Posts: 7

Rep: Reputation: 0
Shell Script - Change user & run multiple commands


Hi folks,

(This may be the wrong forum, apologies if it is)

I'm writing a shell script where the user needs to be changed half-way through then some commands are run by this user. I can do this for one command (e.g. su - X -c "echo 'stuff'"), but doing this for more than one command is proving to be a problem - how would I do this?

Many thanks,
Ian
 
Old 01-26-2009, 07:15 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Have you tried to just separate multiple commands with semi-colon?
Code:
# su - username -c "echo 'stuff'; cd /path/to/dir; pwd; ls"
otherwise you can put all the commands into an executable script and run the script as a single command.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How do i change to super user then revert back to ordinary user ,using shell script? wrapster Solaris / OpenSolaris 6 03-18-2009 04:37 AM
Can my shell script change the password of user ? prabhatsoni Linux - Software 1 05-27-2006 03:06 AM
shell script + change shell && continue darkRoom Programming 6 02-25-2005 03:50 AM
Adding multiple user shell script plexus Programming 2 06-19-2004 09:36 PM
how can i run a shell scripts (or a number of commands )when a user logs in to a linu rddreamz Programming 4 05-20-2004 04:08 PM


All times are GMT -5. The time now is 04:34 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration