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
Related
when I was try to use touch command on my ubuntu bash shell and in my Desktop folder /mnt/c/Users/Public/Desktop$ it give me this touch: cannot touch 'test.txt': Permission denied error.
You may not have access to the /mnt/c/Users/Public/Desktop directory as default
Run:
ls -ld /c/mnt/Users/Public/Desktop
to see whether you have write permissions as default. If you don't run:
sudo chmod +w /mnt/c/Users/Public/Desktop
This will then allow you write permissions to the directory and allow you to create files.
NOTE - Please ensure that the initial bash executable is run as administrator at Windows level
I have an shell script
#!/bin/bash
echo "hello world"
ansible zookservers -i /home/ec2-user/kafka_scripts/ansible_rep/inventory -a "/home/ec2-user/kafka_2.11-0.9.0.0/bin/kafka-server-start.sh kafka_2.11-0.9.0.0/config/server.properties" --sudo
my error was
| FAILED => SSH Error: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
while connecting to 172.30.0.243:22
when I run the ansible command then it is executing
but when I kept it inside a shell script I am getting the above error
my shell is with chmod 777 permission - so the problem it not with shell execution permission
I found something interesting
when I run the script from any other place I'm getting error. but when run it in ansible directory then it is executed.
later when I run it from any other directory it is not throwing any error.
so the problem is with initial public key authentication
I found something intersting -- when I run the script from any other place I'm getting error. but when run it in ansible directory then it is executed
The problem most likely is the location of your ansible.cfg. Ansible will use the config from one of these locations (from the docs):
ANSIBLE_CONFIG (an environment variable)
ansible.cfg (in the current directory)
.ansible.cfg (in the home directory)
/etc/ansible/ansible.cfg
First match wins.
So it uses the config from the "ansible directory", if called from there. If called from any other location there is no ansible.cfg in that directory. Since this is where you have stored you username and private key location the authentication fails.
The best solution seems to be to utilize the environment variable ANSIBLE_CONFIG. Just store the path to your ansible.cfg in there. I think it is /home/ec2-user/kafka_scripts/ansible_rep/ansible.cfg, right?
You can set that variable in your script.
ANSIBLE_CONFIG=/home/ec2-user/kafka_scripts/ansible_rep/ansible.cfg ansible zookservers -i /home/ec2-user/kafka_scripts/ansible_rep/inventory -a "/home/ec2-user/kafka_2.11-0.9.0.0/bin/kafka-server-start.sh kafka_2.11-0.9.0.0/config/server.properties" --sudo
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
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.
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.