Shell script Execute file in tmp directory - linux

I am trying to execute shell script which i have created in tmp folder.
i have granted permission as well to the script using command below.
chmod a+x tmp/test/test.sh
when i run the code i get permission denied error.
[root#server test]# ./test.sh
-bash: ./test.sh: Permission denied

The issue may cause by tmp is noexec, and you can use the sh command to execute the the shell script
sh ./test.sh

Try this workaround:
(. tmp/test/test.sh)

Related

Disk clean up script_error

I am new to scripting and learning and i written a script as shown below to clear all logs under the path /usr/apache/logs
#!/bin/bash
path="/usr/apache/logs/"
for i in $(find $path . -name "*log*");do
cat /dev/null > $i;
done
And after running above script i got the below Output error
/usr/apache/logs/
find: `./lost+found': Permission denied
find: `./root': Permission denied
l_clear.sh: line 4: /usr/apache/logs/: Is a directory
l_clear.sh: line 4: ./Backup/Clients/work_catalog: Is a directory
please help me why i got "find: `./lost+found': Permission denied" even i specified the logs path.
change to root user and
execute your script with root permission.
if use debian:
$ sudo su
# bash your_script.sh
if you use fedora:
$ su -
# bash your_script.sh

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

Tomcat not starting in linux ---permission denied to run startup.sh

I pasted tomcat folder in Linux machine. User is root . When I go to bin folder and execute ./startup.sh I'm getting an error:permission denied. [This is what I got]
How to rectify this issue.
give:
chmod -R 777 startup.sh
Then error will come as:Cannot find ./catalina.sh
then give:
chmod -R 777 catalina.sh
Tomcat will start.
the problem was because there was no permission for executing. u can see if permission is there or not by giving:
ls -l
As color of file name is white, I suppose file is not executable; try the following command
ls -l
It gives you file list with its permission. Try using command
chmod a+x startup.sh
If still permission denied. Try
sudo chmod a+x startup.sh
Then try using
./startup.sh
If still permission denied. Then try
sudo ./startup.sh
Hope it will be helpful.
Verify, that your filesystem with the new tomcat folder isn't mounted with "noexec". Please run a "ls -l", "file start.sh" and a "head start.sh" .
Tom
It is also worthwhile to check which bash you are using with
which bash
This is because you might see the error
Cannot find ./catalina.sh
when your bash is /usr/bin/bash but is working perfectly fine when bash is /usr/bash

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.

Really strange behavior with Linux Shell Scripts

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.

Resources