Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-22-2011, 02:13 AM   #1
LQ Newbie
Registered: Jul 2008
Posts: 8

Rep: Reputation: 0
Changing user and running commands inside of a script?

My current script is as followed:
su et
cd "media/ET"
exec ./ettv.x86 "$@"
That's probably completely wrong, I took the default ET script and tried adding my own additions.

The exact order I need to do things is:
  1. Change users to "et"
  2. CD to "/media/ET"
  3. run ./ettv.x86

I want ET to be run as the user "et" and for some reason, I can't directly su/sudo to run the file without being in the user "et" and the "/media/ET" directory.

This may not be exactly "newbie" but I couldn't find any other forum and I'm hoping someone here can help.

Old 02-22-2011, 09:19 AM   #2
Registered: Sep 2005
Distribution: Gentoo, Sabayon, Puppy, Arch
Posts: 165

Rep: Reputation: 29
How about:

su -c 'cd /media/ET/ && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ettv.x86' - et
Old 02-22-2011, 01:57 PM   #3
LQ Newbie
Registered: Jul 2008
Posts: 8

Original Poster
Rep: Reputation: 0
Originally Posted by headrift View Post
How about:

su -c 'cd /media/ET/ && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ettv.x86' - et
When I tried that, I got this:
cory@Cory-LAPTOP:~$ su -c 'cd /media/ET/ && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ettv.x86' - et
No directory, logging in with HOME=/
-su: line 0: cd: /media/ET/: No such file or directory
I have to be using the 'et' user in able to see/access the '/media/ET' directory. And I can't run the 'ettv.x86' without being in the directory.

It is a bit inconvenient but I guess I don't mind it :P

Also, is there a way to hardcode the password for 'et' into the script? I'm not worried about security issues at all, it's a laptop and it's for a user with access to only one directory.


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
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 10:10 PM
running sed inside script file bajaj111 Linux - Software 9 11-08-2006 10:23 AM
where to place certiain commands inside shell script beeblequix Linux - Newbie 8 08-10-2006 12:12 PM
Running super user commands as normal user mickyg Linux - Security 5 10-14-2005 08:25 PM
changing the user inside a shell script sanjith11 Programming 2 04-22-2004 08:44 AM > Forums > Linux Forums > Linux - Newbie

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

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