I need subprocess in my script to connect with 3G. But unfurtunately it's throwing me alot of errors. So I was hoping maybe someone here could help me.
My code:
import subprocess
import time
subprocess.run('sudo ./sakis3g connect OTHER="USBMODEM" USBMODEM="12d1:1001" APN="internet"', shell=True)
When I run this simple script in my home directory I get the following error:
sudo: ./sakis3g: command not found
Is it maybe because the sakis3g script itself it located in /usr/local/bin. Any help would be appreciated, thanks in advance
I run this simple script in my home directory
./ means the current directory i.e. the home directory in this case.
Is it maybe because the sakis3g script itself it located in /usr/local/bin
/usr/local/bin is (likely) not your home directory. sudo can't find sakis3g in the current directory because there is no such file.
Use /usr/local/bin/sakis3g instead of ./sakis3g.
copy that saskis3g object file in your directory where you have your code then you can use the command directly without including any file path for the object file(i.e sakis3g) in your connect command.
if suppose you have a folder named sample. and your program resides in this folder then copy+paste the sakis3g object file to this folder[you can do this by using the CP command in linux ] and use the normal command ie " system("sudo ./sakis3g connect"); " no need of any path.
Related
I have a docker container with nodejs in it. (node:14.11-alpine3.12)
There is cron running, that executes .sh file with the command:
node /home/parsecsv.js;
Whenever cron executes this command, I get an error
'rror: Cannot find module '/home/parsecsv.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:893:15)
...
I am absolutely sure this file exists, even more, when I go to the container shell and run this command (node /home/parsecsv.js) from the command line it works just fine. What can I do about this?
Check permission of the file, you may debug by giving full permission to file.
add this to your docker file and see if still the issue persists.
RUN chmod 777 /home/parsecsv.js
So, what helped me is to copy js file to /root directory instead of /home. And then change path in work.sh to this: node parsecsv.js It seems like when node is running from sh script it cannot read absolute path or something. That's confusing, but now it is working.
I am trying to install pumba from the OS release page. Once it is downloaded, I try running
pumba --help
It gives a command not found error.
Can anyone suggest what am I missing? The amd_64 file has all read, write and execute permissions.
If the name of the file is pumba_linux_amd64, you have to use that. Additionally, since the file is (assuming) not in your $PATH, you can't launch it directly.
If your file is in your current directory, run
./pumba_linux_amd64
I've been having a lot of trouble trying to set up a path to an executable file in linux. Sorry If it's a dumb question, but I'm new to linux and still figuring things out.
Anyways, the file I want to create a path to is located at:
/opt/gitools/gitools-2.3.1/gitools
So I created a path at the end of my .bashrc file:
export PATH=$PATH:/opt/gitools/gitools-2.3.1/
I've checked, and the file gitools as well as all parent directories are marked as executable. However, when I enter "gitools", it returns:
/bin/bash: /opt/gitools/gitools-2.3.1/gitools: Permission denied
And when I enter "sudo gitools", it returns:
sudo: gitools: command not found
There is nothing wrong with the program itself, because I can run it by going to its directory and entering "sudo ./gitools", however, I'm unsure of why I need sudo when it should be executable for all users.
Any help is greatly appreciated!
I finally figured out a solution that works.
I tried to give full read write execute permission to all files in the program, but that just created errors that prevented running the program at all.
However, I noticed that the owner of all of the files was set to root, so in a last ditch attempt to get it to work I decided to recursively change the ownership of all directories and files associated with the program by going to the /opt directory and entering:
sudo chown -R myUsername:myUsername gitools/
Hope that this might help someone with a similar problem!
I am trying to launch a .sh script from Python 3.3 in Ubuntu 13.10.
The script is supposed to shutdown the computer. I have already marked the sh script as executable through the terminal. I have tried to run the sh script through: os.system("script.sh"), subprocess.Popen("Script.sh"), and subprocess.call([script.sh]).
They keep returning the: OSError Exec format error.
Any help would be greatly appriciated!
I assume that script.sh isn't in your PATH but in your current working directory.
By default os.system and subprocess look in your path for the requested executable. So to execute something in your current working directory you need to specify the executable like this:
subprocess.call("./script.sh")
The ./simply says that the executable that should be executed is in the current working directory.
I am trying to compile ARM code on Ubuntu 12.04 (Precise Pangolin).
Everything is working fine when I put the code in the local directory.
But when I put the code in the cited mount directory, an error shows up:
making testXmlFiles
sh: 0: getcwd() failed: No such file or directory
ARM Compiling xxxxx.c
sh: 0: getcwd() failed: No such file or directory
Here is my setting in fstab:
//10.0.0.1/data /mnt/data cifs auto,noserverino,credentials=/root/.smbcredentials,file_mode=0777,dir_mode=0777,uid=user,gid=users,noperm 0 0
What is going on here? What could cause this error?
This error is usually caused by running a command from a directory that no longer exists.
Try changing your directory and rerun the command.
That also happened to me on a recreated directory. The directory is the same, but to make it work again, just run:
cd .
Try the following command. It worked for me.
cd; cd -
This can happen with symbolic links sometimes. If you experience this issue and you know you are in an existing directory, but your symbolic link may have changed, you can use this command:
cd $(pwd)
In Ubuntu 16.04.3 LTS (Xenial Xerus), the following command works for me:
exit
Then I've login again.
Please check whether the directory path exists or not. This error comes up if the folder doesn't exist from where you are running the command.
Probably you have executed a remove command from the same path on the command line.
If some directory/folder does not exist, but somehow you navigated to that directory, in that case you can see this error.
For example:
currently, you are in the "mno" directory (path = abc/def/ghi/jkl/mno
run "sudo su" and delete mno
go to the "ghi" directory and delete the "jkl" directory
now you are in the "ghi" directory (path abc/def/ghi)
run "exit"
after running the "exit", you will get that error
now you will be in "mno"(path = abc/def/ghi/jkl/mno) folder. That does not exist.
So, generally this error will show when the directory doesn't exist.
To fix this, simply run "cd;" or you can move to any other directory which exists.
In my case, none of the previous answers has worked.
After banging my head against the wall for a while I've found out, that I've destroyed the /etc/passwd entries by running a custom-made-linux-server-setup-bash-script which worked well previously, but this time the regex within the "sed" command erased all the existing entries :D
After copy pasting the default entries from another working Linux server, I could finally restart sshd.
So don't forget to back up the original /etc/passwd file before applying any regular expression replacements on it :)