Double-clicking executable to run a .sh file

General support questions
Post Reply
electronic_guy
Posts: 2
Joined: 2015/01/20 15:50:33

Double-clicking executable to run a .sh file

Post by electronic_guy » 2015/01/20 16:04:22

Hi

I'm a newbie using linux systems but i'm trying to understand how to create a launcher/program that when i click it, it would execute several commands.
I have a shell script with the commands inside.

This is what i have tried (using CentOS 7):

- Installing Alacarte in order to create a Laucher that runs a command.
- On the command i put my shell script location: /home/username/example.sh and click on Lauch in Terminal
- Then i can go to the CentOS Applications menu and click on the Laucher i've just created.

However the program is not executing the instructions inside the example.sh maybe because i need sudo permissions to run them.

This is the content of my example.sh file:

iptables -F
iptables --table nat --append POSTROUTING --out-interface enp2s0 -j MASQUERADE
iptables --append FORWARD --in-interface eno1 -j ACCEPT
echo 1 > /proc/sys/net/ipv4/ip_forward

Do i need the #!/bin/bash or #!/bin/sh header? And why?
Do i need to put gksudo in each line in that file, in order for the launcher to ask me for an authentication?

User avatar
TrevorH
Site Admin
Posts: 33221
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Double-clicking executable to run a .sh file

Post by TrevorH » 2015/01/20 17:43:27

Do i need the #!/bin/bash or #!/bin/sh header? And why?
Yes, you do. Because that's the way the kernel knows what thing to execute.

Yes, iptables needs root access to run it so you need to prefix those commands with sudo. The echo is more complicated so either you need to run the entire shell script as root or take a different approach like running echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

Please note that running this like this is probably not the correct way to accomplish what you want on CentOS 7 as that uses firewalld to manage the firewall and you should probably read up on firewall-cmd as that's the utility to manage firewalld. If firewalld is running then it will randomly overwrite the rules you add and remove them.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

electronic_guy
Posts: 2
Joined: 2015/01/20 15:50:33

Re: Double-clicking executable to run a .sh file

Post by electronic_guy » 2015/01/21 10:58:28

Ok thanks Trevor H. That worked.

Regarding this firewalld overrule i saw this post: http://www.certdepot.net/rhel7-get-started-firewalld/
The comment from november 25th 2014 shows how to disable firewalld program.

Post Reply