LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 02-22-2011, 01:13 AM   #1
cory94bailly
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:
Code:
#!/bin/sh
su et
cd "media/ET"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
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.

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

Rep: Reputation: 29
How about:

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

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

Code:
su -c 'cd /media/ET/ && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ettv.x86' - et
When I tried that, I got this:
Quote:
cory@Cory-LAPTOP:~$ su -c 'cd /media/ET/ && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ettv.x86' - et
Password:
No directory, logging in with HOME=/
-su: line 0: cd: /media/ET/: No such file or directory
cory@Cory-LAPTOP:~$
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.
 
  


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:33 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