Really strange behavior with Linux Shell Scripts - linux

i am really wondering why Linux (Debian Squeeze) is acting kind of crazy.
I've been trying to execute a simple test.sh script in my webapps directory:
/var/www/tomcat7/webapps/ROOT/WEB-INF/bin/
How to execute a script? Well, that would be done by entering:
EDIT: ITS NOT ABOUT WRONG (FORGOTTEN) PERMISSIONS:
chmod +x test.sh
./test.sh
which now gives me the following:
-bash: ./test.sh: No permission
test.sh is looking like this:
#!/bin/bash
echo "Hello!"
What the hek? Copying/Moving test.sh to my home directory and execute it again, which gives me:
Hello!
which is actually the output from my test.sh file. So, it doesnt work in my webapp directory but it works in home?
My researches:
Trying to execute the script with sudo rights:
When executing the script with sudo the script simply does nothing. No messages at all.
Trying to execute it via
. test.sh
It works! But why?

The volume the file is on is mounted noexec. You will need to remount it exec, but consider/research why it was mounted noexec in the first place.

Related

Problems running first shellscript

I'm trying to create my first shell script in bash. I've created the code and I've managed to save the script in my home directory but it wont run. At first I try running it from the home directory with: ./testscript.sh with "permission denied" as a response, i then tried sudo ./testscript.sh and then the "command was not found".
This is my script:
#!/bin/bash
mkdir -p/home/filer
touch /home/filer/fil1
touch /home/filer/fil2
touch /home/filer/fil3
tar-zcvf file.tar.gz /home/filer
So I've tried creating a script that will create a directory called "filer" in my home directory, using touch to create 3 separate files within the "filer" directory and then creating a tar.archive out of the whole "filer" directory. I think the script is correct, I could just use a hand running the script.
Other than a couple of typos (mkdir -p/path -> mkdir -p /path, tar-zcvf ... -> tar -zcvf ...), you should refer to your home directory using $HOME environment variable. /home/filer is an absolute directory path, which I am assuming, is not your actual home directory.
#!/bin/bash
mkdir -p $HOME/filer
touch $HOME/filer/fil1
touch $HOME/filer/fil2
touch $HOME/filer/fil3
tar -zcvf file.tar.gz $HOME/filer
You can execute the script, ./testscript.sh as bash testscript.sh or ./testscript.sh.
In the second case, the script need to have proper executable permissions. chmod +x ./testscript.sh gives it full executable permissions.

execute linux shell permisson denied,but i have assigned permissions,how can i fix it?

I write a shell named test.sh in /run path and execute chmod 777 test.sh command.
then I run ./test.sh ,it displays permission denied.
but I run sh test.sh,it's ok.
Then I copy test.sh to my home directory and run ./test.sh ,it works.
can somebody tell me why?
my problem

sudo: unable to excute ./blah.sh: No such file or directory

I got this error
sudo: unable to excute ./blah.sh: No such file or directory
my code is every simple
#!/bin/bash
echo "blah"
And I'm sure that I've changed the permission to "rwx". When I try sudo bash blah.sh, I will get the output. But I still cant execute the file. And I'm in debian OS.
Anyone knows why?
make it executable
sudo chmod a+x ./blah.sh
that sets the executable bit for all users just
+x
for your single user
Check in /etc/sudoers if your username is allowed to sudo.

Permission issues, not able to run script as root

I am running a shell script(Script.sh) which, itself, is calling other shell scripts(
Script2.sh, Script3.sh ...etc). I logged in as a root user and have given execution permission to all the scripts. But on when I execute "ls -l" the scripts still dont have execution permissions displayed on file attributes column. "Script.sh" runs by following syntax:
root#freescale $ sh Script.sh
But this script is not able to execute other scripts(Script2.sh, Script3.sh) being called by it. Error is reported as "Permission denied"
I already gave execution permission by chmod command but then also neither the permissions are changing nor the scripts(Script2.sh, Script3.sh ..) are executing.
I hope this error is due to the reason that Script2.sh are called in Script3.sh as:
./Script2.sh
./Script3.sh
And if I write it as :
sh Script2.sh
It executes but doesn't able to execute other script which are called inside Script2.sh and reports same error as "Permission Denied"
Make sure that your partition is not mounted with the noexec flag (which - as the name suggests - prevents making any files executable)
Kindly make sure the permission and ownership for the script.sh file, also try
# chmod 755 script.sh
# chown root.root script.sh
Thanks.

Having trouble writing my first bash script

ok I am writing my first bash script in ubuntu 10.04.
The file is on my desktop: /home/myuser/Desktop
The file is called hello-world
The file contains:
#!/bin/bash
echo "Hello World"
I open a command line and run:
/home/myuser/Desktop/hello-world
It tells me permition is denied. So I run it again with sudo, it asks me for my password, I type it in, hit return.
I get this output.
sudo:
/home/myuser/Desktop/hello-world:
command not found
What am I doing wrong?
Your script probably is not set to be executable. Try:
chmod u+x /home/myuser/Desktop/hello-world
If your script is called test.sh then do the following...
$ chmod +x test.sh
followed by
$ ./test.sh
chmod +x hello-world
You need to mark the script as executable. Run chmod +x hello-world to add the executable bit.
You can also do:
sh /home/myuser/Desktop/hello-world
which will execute the script without it needing to be set as executable.

Resources