bash: ./mybashfile.sh: Permission denied [duplicate] - linux

This question already has answers here:
-bash: ./manage.py: Permission denied
(4 answers)
Closed 7 years ago.
I created a bash file mybashfile.sh containing below commands, but running it in the terminal giving me a Permission Denied Error I tried running the file from su but same Permission Denied Error for su.
I am running the command like this -
$: ./mybashfile.sh
It is in a directory containing mybashfile.sh
My mybashfile.sh file -
#!/usr/bin/env bash
redis-server --save "" &
sleep 1
redis-cli flushall
cd ~/Documents/class-prj/class-prj
npm run app.js
Let me know what I am doing wrong here.

Set the mode to executable:
chmod +x mybashfile.sh

Related

Shell script Execute file in tmp directory

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)

sudo jq query permission denied [duplicate]

This question already has answers here:
How do I use sudo to redirect output to a location I don't have permission to write to? [closed]
(15 answers)
Closed 4 years ago.
Im trying to use jq to alter a json file via a script.
in my terminal im trying to run this, but getting a permission denied error. Im able to change it using a sudo nano manually.
sudo jq -c '.interpreterSettings."2ANGGHHMQ"."properties"."zeppelin.pyspark.python" = "python3"' interpreter.json > tmp.$$.json && mv tmp.$$.json interpreter.json
Any ideas on why?
Thanks,
Tim
Simple fix, just gave user permissions on directory.
sudo chmod -R 777 /etc/zeppelin/conf

sudo in bash, permission denied [duplicate]

This question already has answers here:
How do I use sudo to redirect output to a location I don't have permission to write to? [closed]
(15 answers)
Closed 7 years ago.
I want to block usb mass storage in some of the systems in the LAN. I have written a bash script which will modify the file. I am running the script as default admin in ubuntu. But the script is not able to modify the file. I am getting the following error
"bash: /etc/modprobe.d/blacklist.conf: Permission denied"
Below is my bash script
#/bin/bash
password='mypassword' #admin password of remote system
val='blacklist usb-storage' #text which i want to add in the file
for sysName in $(cat systemDetails) #systemDetails is file which stores
do
ssh $sysName 'echo '$password' | sudo -S echo '$val ' >> /etc/modprobe.d/blacklist.conf'
echo
done
#script ends
NOTE: I have configured my system such that no ssh password is required.
Any pointers in this regard will be really helpful.
Try this:
ssh $sysName "echo $password | sudo -S sh -c 'echo $val >> /etc/modprobe.d/blacklist.conf'"

crontab permission denied error [duplicate]

This question already has answers here:
Permission denied with bash.sh to run cron
(6 answers)
Closed 2 years ago.
I put a file.sh for crontab to execute and redirecting the output into an email to my mailox. The script works when I run it manually. Unfortunately, when crontab does the job, it has the following error (from the output sent to me):
/bin/sh: /home/zenoss/zen-remote-bkup.sh: Permission denied
My crontab setup is the following:
30 11 * * * /home/zenoss/zen-remote-bkup.sh 2>&1 | mail -s "Zenoss backup replication" email#abc.com
And these are the permission on the file.sh I need to execute:
-rw-rw-r-- 1 zenoss zenoss 1433 Nov 5 10:32 zen-remote-bkup.sh
[zenoss#server1 ~]$
Does anyone know which permission I am missing? Thank you.
You have to put the eXecutable bit on the script to do the job:
chmod +x /home/zenoss/zen-remote-bkup.sh

How to append to /etc/hosts file from the termimal? [duplicate]

This question already has answers here:
How do I use sudo to redirect output to a location I don't have permission to write to? [closed]
(15 answers)
Closed 8 years ago.
I'm trying to append to the /etc/hosts file from the termimal:
sudo echo -e "127.0.0.1 localhost-myproject" >> /etc/hosts
Even though I'm doing as sudo, it won't let me. I get permission denied:
bash: /etc/hosts: Permission denied
I've looked at a couple other posts and they instruct like this. But I'm getting this error. How can I do this? Thanks
sudo /bin/bash -c 'echo -e "127.0.0.1 localhost-myproject" >> /etc/hosts'

Resources