CMD terminal pass array of args - shell

Im running the following commands in array it works !
command: ["k6", "run", "/etc/config/load_test.js"]
Now when I add just
--compatibility-mode=base
I got error , I try it like this
command: ["k6", "run", "--compatibility-mode", "base", "/etc/config/load_test.js"]
Any idea what im doing wrong? https://k6.io/docs/testing-guides/running-large-tests#compatibility-mode=base
error: accept one arg(s) receive 2
if I pass it to to the terminal like this it works
k6 run --compatibility-mode=base someplace/myscript.es5.js
But not sure how to put it in array of args
I've tried also
command: ["k6", "run", "--compatibility-mode=base", "/etc/config/load_test.js"] which doesnt work either ...

Have you tried this one:
command: ["k6", "run", "--compatibility-mode=base", "/etc/config/load_test.js"]

Related

Error when run simple shell script on opensuse15.1: SubEntry: number of args (2) is invalid

The following error occurred every time I tried to run a simple shell script(test.sh):
SubEntry: number of args (2) is invalid
This single line code is in the test.sh:echo -e 'open 192.168.1.123 \nuser root pass \nput test.csv \nquit'|ftp -inv
If I run the code line directly in the command line works OK: the file test.csv is transferred successfully via FTP on server 192.168.1.123.
Any one know why I get that error when I run the shell script?!Thank you!
I found another solution for sending files via FTP using a script.
I use curl to send the file like this:
curl -T your_file ftp://your_IP
This command can be put in a script and automatic run that script.Works for me.

s3cmd put command: Upload: Command not found

So I want to put a file onto s3. Here is the cmd:
/usr/bin/s3cmd --rr --access_key="$access_key" --secret_key="$secret_key" put "$FILEPATH/$ZIPPED_FILE" "$s3_path/$ZIPPED_FILE"
And this works perfectly except in my bash shell, it prints out this message: upload:: command not found. Anyone encounter this?
This almost certainly means you're running the stdout of s3cmd as a command itself. For instance, that could happen if you were to run:
# BAD: runs the command, then runs its output as another command
`/usr/bin/s3cmd --rr --access_key="$access_key" --secret_key="$secret_key" put "$FILEPATH/$ZIPPED_FILE" "$s3_path/$ZIPPED_FILE"`
To fix that, just take the backticks out, and write:
# GOOD: just invokes your command, with its output written to stdout
/usr/bin/s3cmd --rr --access_key="$access_key" --secret_key="$secret_key" put "$FILEPATH/$ZIPPED_FILE" "$s3_path/$ZIPPED_FILE"

Python issue running subprocess.Popen() from a .py in console

I am running a program which uses subprocess.Popen() in order to do some tasks (I cannot use os.system() for them). The program, which correctly runs within an IDE (I will explain later) stops when I run it from the console, although I can resume it by writing fg in the console.
The code is the following (this is a piece of code,the full code implements similar tasks to which the same problem occurs)...
import subprocess
p,o = subprocess.Popen(['/bin/bash', '-c', '-i', 'which python3.5'], stdout=subprocess.PIPE).communicate()
p = p.decode('ascii')
print(p)
print('Installing pysamstats...')
subprocess.Popen(['/bin/bash', '-c', '-i', 'conda install -y -c bioconda pysamstats']).communicate()
print('OK')
If the code is run from an IDE (I use PyCharm with anaconda as interpreter) the output occurs and all the script runs smoothly, with the exception that the following message appears each time Popen is called...
bash: cannot set terminal process group (3556): Inappropriate ioctl for device
bash: no job control in this shell
With the exception of the "error", as I have said, the code is correctly executed.
However, if I run the .py file from the console...
python3 '/DIRTOFILE/ZZZ.py'
The following message appears...
/home/labcombio1/anaconda3/bin/python3.5
Installing pysamstats...
[1]+ Stopped python3 '/media/labcombio1/ZZZ.py'
That is, the first command is executed, and the output is correctly printed, whereas the second command is stopped. If I resume the command with fg, it works fine. The same happens if the first Popen command is not run, that is, only with the second one.
I have tried shell=True, removing .communicate(), adding stdout=subprocess.PIPE, and none of these things solves the "Stopped" line at the console. Other commands yield the same results.
Finally, I have tried running the following commands:
subprocess.Popen('conda install -y -c bioconda pysamstats', shell=True).communicate()
subprocess.Popen(['/bin/bash', '-c', 'conda install -y -c bioconda pysamstats']).communicate()
And although they both work correctly in Pycharm (they don't even prompt bash: cannot set terminal process group (3556): Inappropriate ioctl for device), the terminal still fails, with the following message:
/bin/sh: 1: conda: not found
I know little about subprocess module, and despite reading other questions and some pages taking about it, I have been unable to solve that problem.
Thank you in advance
First problem:
bash: cannot set terminal process group (3556): Inappropriate ioctl for device
bash: no job control in this shell
Remove -i flag from bashinterpreter.
-i If the -i option is present, the shell is interactive.
Example:
p, o = subprocess.Popen(['/bin/bash', '-c', 'which python3.5'], stdout=subprocess.PIPE).communicate()
Second issue:
/bin/sh: 1: conda: not found
The condapath is not exported in your environment.
Possible Solutions
1) Load it in your IDE.
2) Use the full path to the executable.
subprocess.Popen(['/path/to/conda/conda', 'install', '-y', '-c', 'bioconda', 'pysamstats']).communicate()
3) Pass an env to Popen.
subprocess.Popen(['conda', 'install', '-y', '-c', 'bioconda', 'pysamstats'], env={"PATH": "/path/to/conda"}).communicate()

Is it possible to write a shell command that connects to Heroku and runs a Ruby command?

Is it possible to script the following on OSX?
heroku run console
load 'init.rb'
The following does not work:
alias 'heroku_init=heroku run console; load "init.rb"'
It seems that the shell has to wait for the Heroku console to connect, or needs a way to send the load command to the Heroku console instead of the bash shell.
Big ups to camilo-santana for the answer:
#!/usr/bin/expect -f
set timeout -1
spawn heroku console
expect "irb(main):001:0>"
send "load 'app/init.rb'\r"
interact
It can also be done with an alias:
alias 'hc=heroku run console -- -r ./app/init.rb'
What you want it to send load 'init.rb' to the standard input of the heroku run console program. You do that in the shell using the pipe operator:
echo "load 'init.rb'" | heroku run console
This works but notice it makes the console hang, if you want to input some more commands manually you can do:
{ echo "load 'init.rb'"; cat } | heroku run console
Hope this helps ;)

Running a PHP CLI Script from a PHP Application

I have a php file which needs to be executed in CLI from my Php application which runs on CodeIgniter framework. I tried the exec and shell_exec command and it seems to not start the process. Please find the code below which I try to execute.
$phpPath = exec('which php');
$cmd = $phpPath.' '.dirname(__DIR__).'/API/notification/NotificationServer.php';
echo "<pre>".shell_exec($cmd)."</pre>";
When I try running the above in Terminal it executes fine. I need to automatically trigger this once the user has a session set.
The path/$cmd variable prints
when I print the variable $cmd i get the below output, and the below when given in terminal works fine.
/usr/bin/php /Users/lalithb/Desktop/Android/AndroidWS/API/notification/NotificationServer.php
the above command works fine in the Terminal. When i try to exec/shell_exec it, it is not working.
APACHE_ERROR LOGS ARE :
sh: line 1: 2437 Trace/BPT trap: 5 /usr/bin/php
sh: line 1: /Users/lalithb/Desktop/Android/AndroidWS/API/notification/NotificationServer.php: Permission denied
Can someone help me out in running this above code in CLI ?
I solved the problem, Guess there would be someone else like me trying to access the restricted folders. I found the solution here
http://ubuntuforums.org/showthread.php?t=1302259
exec('chmod +x'.dirname(__DIR__).'/API/notification/NotificationServer.php);
The above worked the magic.

Resources