7

I have a few basic commands that I need to run on a Red Hat Linux 5 Virtual Machine with GNOME to start a couple servers.

Example

cd /home/user/scripts  
sh runTHISthing.sh pub  
cd /home/user/logs  
tailf pub.log  

Not a crazy amount of code but sometimes I restart VM several times a day. In Windows, I would probably just create a batch file and put it on my desktop. Then it's just a matter of double clicking and off it goes.

Is there anyway to do the same in Linux? I've tried to create a launcher that just runs the emtpy file in terminal with no result.

2
  • You even got the right tag for this. It's called a shell script. What exactly are you missing?
    – Mat
    Commented Aug 2, 2012 at 15:09
  • 1
    @Mat I'm looking for a double click functionality. I want the file to sit on my desktop and I just double click, opens the terminal and runs the script. I know the a shell script is what I'm looking for, but I'm probably into hour 2 of my overall Linux experience and 30 minutes into Red Hat specifically. I did the research, it's just not working how I want. Commented Aug 2, 2012 at 15:15

1 Answer 1

10

In UNIX, a 'batchfile' is known as a shell script. A typical BASH shell script will start with a magic line that tells the operating system which shell to execute the script with, so your example would end up:

 #!/bin/bash

 cd /home/user/scripts   
 sh runTHISthing.sh pub   
 cd /home/user/logs  
 tailf pub.log

NOTE: After you create the file, you have to mark it as executable, in order for the OS to try executing it:

chmod +x myscript
2
  • Sorry, that last part about marking it executable. How would I do that? Commented Aug 2, 2012 at 15:18
  • In a terminal window, issue the command "chmod +x scriptfilename", with the correct path to your script.
    – Don Simon
    Commented Aug 2, 2012 at 15:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .