Permission issues, not able to run script as root - linux

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.

Related

Getting permission denied while executing shell script in jenkins pipeline

I have created new user as admin in linux and given required permissions ( Added in visudo ).
I have just created new folder and added script to it as below.
/home/admin/test/1.sh
sh contains below
#!/bin/bash
echo hello
then given executable permission to the 1.sh.
chmod +x 1.sh and also given full permissions to the folders as well.
chmod 777 test and it is working fine when i executed directly in linux server.
Created jenkins pipeline job as below.
pipeline {
agent any
stages {
stage ('Testing bash script') {
steps {
sh '/home/admin/test/1.sh'
}
}
}
}
When i have executed it in jenkins then got below error. Not sure why it is getting failed.
Please help here.
/var/lib/jenkins/workspace/TestScript#tmp/durable-c6024b58/script.sh: line 1: /home/admin/test/1.sh: Permission denied
Try changing chmod +x 1.sh into chmod a+rx 1.sh.
Let me know if it worked.
Regards.
I've had the same issue and to solve I simply created a new script, added execution permissions from the start, and changed the references in my Jenkinsfile (ofc).
After doing this somehow I could overcome the error.
You didn't say what exactly system you are using but eg if it's Centos it can be related to SELinux so you can switch it into permissive mode and try again. Anyway good thing to do is to switch to user jenkins (or any other that is used to run Jenkins) using sudo / su and then try to execute this script from shell. To list privileges on whole path where script is located is convenient to use namei -l /home/admin/test/1.sh

Bash script not running , user issue

i've created a bash script batch-create-users.sh and I want execute it from the terminal, Im on the folder when the script is and I run the command
./batch-create-users.sh and I got error
the file './batch-create-users.sh' is not executable by this user
I entered as sudo -s and give the password but it doesn't help, any idea?
Give execute privilege to the file before executing.
chmod +x batch-create-users.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

Incron job is not being executed

I am using incron to monitor one of my file in /var/www/html directory.
output of incrontab -l
/var/www/html/test IN_ACCESS /home/intel/test.sh
This job is supposed to create a file in home directory, But when this job got executed (I opened the web address in browser), no file is created, following line is whon shown in /var/log/cron file
Jan 20 10:27:57 localhost incrond[26442]: (root) CMD (/home/intel/test.sh)
This clearly shows that event had occurred.
P.S: If I just run a /home/intel/test.sh in CLI its works fine and creates test file, following is my test.sh file.
#!/bin/bash
touch fm00
Mostly this problem occurs due to script file permission and ownership of script files. The same problem was faced by me. I found that my scrip owner was not a super user e.g. root.
So, you have to set the permission and ownership of your scrip as super user. Find below.
First of all edit your crontab as super user.(in RHEL like below)
[abc#host] crontab -e
and save crontab :wq!
Now set permission for script
[abc#host] chmod +x script.sh
[abc#host] chown root:root script.sh
Now restart your crontab.(in RHEL like below)
[abc#host] /etc/init.d/crond restart

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