LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 03-22-2005, 04:36 PM   #1
Fillys6
Member
 
Registered: Mar 2005
Posts: 31

Rep: Reputation: 15
How to run a text file through a command prompt?


I have a text file that looks like this:

su myuser
umask 0000
TERM=vt220;export TERM
./program


I want to run this text file through a terminal by clicking on it. Right now it just runs the first line in the text file. If I copy and paste the text file into the terminal window, it executes everything fine. Someone recommended that I add #!/bin/bash to the top, but that didn't work.

Thanks for any help.

ps this is with Red Hat ES3 and the GNOME gui.
 
Old 03-22-2005, 04:40 PM   #2
calcon
Member
 
Registered: Mar 2005
Location: somewhere over the rainbow theres a place....
Distribution: Ubuntu Dapper and Arch
Posts: 121

Rep: Reputation: 15
I know that someone said to add it but try again:
Make the file look like this:
Code:
#!/bin/bash
su myuser
umask 0000
TERM=vt220;export TERM
./program
Then to run it, start the terminal and type
Code:
./nameofscript
calcon
 
Old 03-22-2005, 04:43 PM   #3
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 46
I'm not sure what you're trying to accomplish here, but anyway... when you "su myuser", a new shell will be created and the script execution stopped until you exit this new shell (after that rest of the script does get run, but only after that). What you need to do is run "su myuser -c scriptname". So "su myser" doesn't go inside the script but is entered from the commandline when you want to run the script. Hope this helps.
 
Old 03-22-2005, 04:57 PM   #4
Fillys6
Member
 
Registered: Mar 2005
Posts: 31

Original Poster
Rep: Reputation: 15
Well the reason for the "su myuser" is because the user logged in at the console is a different user than what the "./program" needs to run under.

I am going to give this a try right now and see what happens. I basically just want to be able to double click on this text file and it will run the whole command. This will prevent the user from needing to type each line (there is more than what I posted).

Ill post back in a few mins and let you know if it worked.

Thanks.
 
Old 03-22-2005, 05:09 PM   #5
calcon
Member
 
Registered: Mar 2005
Location: somewhere over the rainbow theres a place....
Distribution: Ubuntu Dapper and Arch
Posts: 121

Rep: Reputation: 15
Ahhhh!

I see what you mean!
You want to have like an icon on the desktop and that be the file?
Ah, I tried to do that before and I can't get it to work, so let us know how it works!

calcon
 
Old 03-22-2005, 05:16 PM   #6
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 46
Also take into account that su will want you to type in the password for "myuser" before executing the script. If you want to doubleclick on some icon or something, you will need a way to enter the password. Xterm will do, so use:

xterm -e "su myuser -c scriptname"

A fancier way would be to use utility like gksu (a GTK/GNOME version of su, I'm sure there is also a version for QT/KDE).

You could do something like:

#! /bin/bash
if [ ! $1 ]; then
xterm -e su myuser -c "$0 x"
else
umask 0000
TERM=vt220;export TERM
./program
fi

if you want su command to be inside the script also.

sudo command will let you do all of this without giving a password, but then you will need to add an entry to /etc/sudoers using visudo command.

Last edited by alienDog; 03-22-2005 at 05:41 PM.
 
Old 03-22-2005, 06:31 PM   #7
calcon
Member
 
Registered: Mar 2005
Location: somewhere over the rainbow theres a place....
Distribution: Ubuntu Dapper and Arch
Posts: 121

Rep: Reputation: 15
So if I want to execute a command like say "mount /mnt/usb", I make the script like:
Code:
#!/bin/bash
xterm -e "mount /mnt/usb"
?

calcon
 
Old 03-24-2005, 06:59 AM   #8
alienDog
Member
 
Registered: Apr 2004
Location: Europe
Distribution: Debian, Slackware
Posts: 505

Rep: Reputation: 46
For mount command you probably wouldn't need xterm because there is no need for you to interact with the command (mount doesn't ask you anything unlike su does with the password). You would just make it:

#!/bin/bash
mount /mnt/usb
 
Old 03-24-2005, 03:21 PM   #9
calcon
Member
 
Registered: Mar 2005
Location: somewhere over the rainbow theres a place....
Distribution: Ubuntu Dapper and Arch
Posts: 121

Rep: Reputation: 15
Ok... I'll try that next time I want to mount my usb thumbdrive, thanks (I am going to put a script for mounting and unmounting on my desktop to make it easier.)
 
  


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
execute php file on command prompt robberttheman Linux - Newbie 0 09-23-2004 02:24 PM
How do you copy and paste a file from a command prompt? thenewguy05 Linux - Newbie 6 07-13-2004 04:41 PM
typing a program name in the command prompt to run it iammeuno Linux - Newbie 1 12-19-2003 02:11 PM
File that defines root command prompt? WeNdeL Linux - Newbie 6 11-20-2002 01:28 PM
How to play a wav file from the Command Prompt arraman Linux - General 1 08-02-2001 08:13 AM


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