I recently installed Go onto our server with CentOS 6.3. The install appears to have gone fine. However I made a test "hello world" script, and when I run I get the following output.
fork/exec /tmp/go-build967564990/command-line-arguments/_obj/a.out: permission denied
Now running go env or other go commands seem to work. At first I figured it was a permission issue, however running as root user I get the same thing. An
I encountered this issue today but the solutions above did not work. Mine was fixed by simply running:
$ export TMPDIR=~/tmp/
then I was able to get the script to run with:
$ go run hello.go
hello, world
The only downside is you have to run export TMPDIR every time you want to run an application.
Kudos to Adam Goforth
Just guessing: Your nix perhaps disables for security reasons executing programs in /tmp. It might be configurable in CentOS, but I don't know that.
The alternative solution: It seems you're trying go run to execute a Go program (which is as script as C is a script). Try (assuming $GOPATH=~, the easy possibility) instead a normal build, i.e. instead of
me:~/src/foo$ go run main.go
try
me:~/src/foo$ go build # main.go should not be necessary here
me:~/src/foo$ ./foo
This approach will still use /tmp-whatever to create the binary, IIRC, but it will not attempt to execute it from there.
PS: Do not run these command as root. No need for that with correct setup.
I am using Fedora 31 and got a similar error which brought me here. I could not run the Go debugger used by Jetbrains IntelliJ Ultimate/GoLand without fork/exec & permission denied error. The solution was this:
setsebool deny_ptrace 0
See https://fedoraproject.org/wiki/Features/SELinuxDenyPtrace for details.
exec.Command return this sturct: type Cmd
standard comment:
// Dir specifies the working directory of the command.
// If Dir is the empty string, Run runs the command in the
// calling process's current directory.
Dir string
so resolve, you can pass the exec cmd's path to exec yourself command:
cmd := exec.Command(xxxxx)
cmd.Dir = xxxxPath
and then you can call Run() or other Output() func
Instead of settings TMPDIR which might affect other programs, you can set GOTMPDIR:
mkdir /some/where/gotmp
export GOTMPDIR=/some/where/gotmp
Then add export GOTMPDIR=/some/where/gotmp to your profile (i.e. .bash_profile) to make the variable permanent.
To fix this issue on my Chromebook I just remounted /tmp as executable. There may be security implications in doing this, but since go run works on other platforms I figure maybe it's not that bad (especially on a local dev machine):
sudo mount -i -o remount,exec /tmp/
I added this to my .bash_profile script.
Consider trying:
sudo mount -o remount exec /tmp
Related
I am in the process of Citrix Workspace on Ubuntu Mate. I have followed the directions provided at this link: https://jamesjmeyer210.github.io/site/blogs/installing-citrix-workspace-on-ubuntu.html
However this command specified on the page for certificate setup fails:
$ exec ctx_reash
bash: exec: ctx_rehash: not found
Running exec without any parameters completes silently, so bash definitely recognizes the command.
I have searched the internet and most of the example show redirect after "exec" and before the file specified.
I had the same challenge (Mint 20.2)
In my case I just ran the ctx_hash file by going to the relevant directory and typing
./ctx_hash
that worked, "exec ctx_hash" will not work. But the file is executable so I didn't need to change permissions or anything and was able to run it fine. This resolved the problem.
I try to run a gmt-script and get the message:
bash-3.2$ plot_scenario.gmt
bash: plot_scenario.gmt: command not found
Does anyone know what could fix the problem?
I got a script from my supervisor, and it worked just fine on the uni Linux pc.
I have a Mac OS.
When you type text in shell, it tries to look for available commands. Here bash doesn't find any command like plot_scenario.gmt and outputs command not found.
The proper way to execute a file is ./filename where . refers to current directory. But you need to give execution permission to file you want to run. So, following commands may help you:
chmod +x <filename>
./<filename>
Note that make sure your pwd is where you're file is located. Another way to run or execute file is calling the shell:
bash /path/to/file
I'm trying to write a script shell (Mac OS X) for deploying my Awestruct site within a launch agent.
So, I have to generate site before deploying it. The command to generate site is :
awestruct -g
My script is myscript.sh :
cd /my/site/structure/base/directory
awestruct -g
This script is launched by the system when an event occurs.
But the problem is it doesn't know about awestruct...
My awestruct program is a part of my ruby installation and is added to my PATH variable.
When I run the script manually, it works (because it's my user who is lauynching it)
When the system detect the event and runs the script, it results as :
awestruct: command not found
The problem is the PATH...
If it works manually, then in the same prompt where it works, run command:
which awestruct
That will print the program file with full path, let's assume /usr/local/bin/awestruct, but use whatever it really is. Then use that in your script, for example:
cd /my/site/structure/base/directory
/usr/local/bin/awestruct -g
This assumes that there are no other environment variables, only defined for your account, which awestruct needs. If there are, then find out what they are, and add them to your script before running awestruct, for example with line:
export AWESTRUCT_ENVIRONMENT_VARIABLE=foobar
(Note: When you run the script normally like any program, that will not change the parent shell environment.)
You can also add the path to the executable in the PATH of the user that run the script and gets the error.
You could try something like :
$ su - <user_that_run_the_script>
$ echo "export PATH=$PATH:$(which awestruct)" >> ~/.bash_profile
$ source ~/.bash_profile
(For Linux users, use ~/.bashrc instead of ~/.bash_profile)
I'm using this script:
https://github.com/gilleswittenberg/BackupSql/blob/master/BackupSqlShell.php
But when I run cake BackupSql from my terminal within my console folder I get this error:
Error: Shell class BackupSqlShell could not be found.
I have put BackupSqlShell.php inside app/Console/Command/
Am I doing this right?
You should run shells in 2.x as follows (from the app dir):
Console/cake FooBar
You can run Console/cake which will output what is available. Try it and see if your shell is showing.
If it is, make sure you type it correctly, copy paste to be sure.
If its not, check permissions and location is 100% correct, eg: case and so on.
Edit: You can not, ever, run shells from Console/Command. always from APP dir.
I am trying to setup up Amazon's EC2 service and am having some trouble.
I have downloaded the Amazon EC2 API Tools, which I've put in a folder ~/.ec2 along with my .cert and .pemfiles.
When I attempt any command from ~/.ec2/bin I get an error /Users/zmjones/.ec2/bin/ec2-cmd: /usr/bin/env: bad interpreter: Operation not permitted. I asked about this in "/usr/bin/env bad interpreter".
Now that I have removed the DOS line-endings using variants of this mv /users/zmjones/.ec2/bin/ec2-add-keypair /users/zmjones/.ec2/bin/ec2-add-keypair.bak
tr -d '\r' < /users/zmjones/.ec2/bin/ec2-add-keypair.bak > /users/zmjones/.ec2/bin/ec2-add-keypair, I've tried to execute some of the commands in ~/.ec2/bin and have been unable to get it to work.
I've gotten a permission denied error, which when I then use sudo, tells me that the environment variable EC2_HOME doesn't exist, while echo $EC2_HOME indicates that it does. Here is my ~/.bash_profile.
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:$PATH
PATH=/opt/local/sbin:/usr/local/bin:/usr/x11/bin:/usr/texbin:$PATH
PATH=/usr/local/texlive/2011/bin/x86_64-darwin:$PATH
PATH=/Library/Frameworks/EPD64.framework/Versions/Current/bin:$PATH
EC2_HOME=~/.ec2
PATH=$EC2_HOME/bin:$PATH
EC2_PRIVATE_KEY=`ls $EC2_HOME/pk-*.pem`
EC2_CERT=`ls $EC2_HOME/cert-*.pem`
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home/
export PATH
You're getting a "permission denied" error because the execute (+x) bit is not set on your modified script.
Do not use sudo to fix this.
Simply set the +x bit:
chmod +x /users/zmjones/.ec2/bin/ec2-add-keypair
(and the same for your other scripts with fixed line endings).
The reason sudo didn't work is that by default it starts with a clean environment, without your EC2_HOME and other environment variables.
The reason you don't want to use sudo to fix the problem anyway, is that running with sudo runs the whole program as root, which has the possibility of doing bad things on your system. At the very least, it might create files or subdirectories in your local directory that are owned by root, which you then have to take extra steps to modify/delete later. At worst, a bug in the program could wipe out your whole system, or important parts of it.
If ls -al# shows com.apple.quarantine extended attrib, the files won't be executed. You'll need
xattr -d com.apple.quarantine filename