Bash script not running , user issue - linux

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

Related

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.

ssh command to run remote script exist shell on remote server when switching user

When I run a script such as this:
ssh -t root#10.10.10.10 '/tmp/somescript.sh'
where the script is defined as:
#!/bin/sh
mkdir -p /data/workday/cred
chown -R myuser:myuser /data
su myuser - # <------- NOTICE THIS ! ! ! !
rpm -Uvp --force --nodeps --prefix /data/place /data/RPMs/myrpm.rpm
Notice the above su command.
If I comment-out the su command, the script runs remotely and then my shell prompt returns to where I came from ( same server where I ran the ssh command above )
But leaving the script as listed above, causes the script to complete successfully but the shell prompt stays on the remote server.
How can I prevent that ? Making sure that the issuer of the rpm command is a different user than root just a listed ?
But leaving the script as listed above, causes the script to complete successfully but the shell prompt stays on the remote server.
Not exactly. The script is running up to the su command, which spawns a new subshell, and stopping there until you exit the shell. Until you exit that shell, the rpm command never runs, and when it does, it runs as root.
If you want to run the rpm command as a non-root user, you'd need to do something a little different, like:
sudo -u myuser rpm -Uvp ...
add 'exit' at the end of your script

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.

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