How to run CLI command "hangup request" with Java code - command-line

I need run this with Java
String command = "asterisk -rx \"hangup request ...\"" ;
but i got return i such command '"hangup'.
asterisk -rx "hangup request ..."
okay when i type and run with CLI.
Is there any solution?

Use
System.exec(new String[]{"asterisk","-rx","hangup request ..."})
instead. System.exec(String cmd) does not honor any embedded quoting and splits the supplied string into pieces with "\s+" pattern.

You should not start enother copy of asterisk just for run hangup request.
Correct solution is use AMI interface to request hangup.

Related

How do I run Jmeter test from command line with -Djava.rmi.server.hostname=IP and command line parameter?

I need to run a distributed test with some of the command line parameter and also I need to pass My server IP with -Djava.rmi.server.hostname=IP, since I am running it from the command line I need nee to give as
jmeter -n -t C:\\Jmxfile.jmx -r Gsomeproperty=value in command line.
I am confused of passing even the command line parameter and also hostname? can somebody help me in sending both at a time.
Check the documentation:
Java system properties and JMeter properties can be overridden directly on the command line (instead of modifying jmeter.properties). To do so, use the following options:
-D[prop_name]=[value]
defines a java system property value.
-J[prop_name]=[value]
defines a local JMeter property.
-G[prop_name]=[value]
defines a JMeter property to be sent to all remote servers.
-G[propertyfile]
defines a file containing JMeter properties to be sent to all remote servers.
So, you can send both at a time through the command line.

wget returns with 500: Internal error, but browser works

I am trying to download the contents of this link >
http://goldsmr2.sci.gsfc.nasa.gov/daac-bin/OTF/HTTP_services.cgi?FILENAME=%2Fdata%2Fs4pa%2FMERRA%2FMAT1NXSLV.5.2.0%2F2014%2F01%2FMERRA300.prod.assim.tavg1_2d_slv_Nx.20140103.hdf&FORMAT=TmV0Q0RGLw&BBOX=-16%2C-44%2C-11%2C-40&LABEL=MERRA300.prod.assim.tavg1_2d_slv_Nx.20140103.SUB.nc&FLAGS=&SHORTNAME=MAT1NXSLV&SERVICE=SUBSET_LATS4D&LAYERS=&VERSION=1.02&VARIABLES=u10m%2Cu50m%2Cv10m%2Cv50m
through wget but I get an internal error 500 instead. It works when I paste the url into firefox.
I have tried some options with wget and even using a proxy but nothing seems to work. Help is very much appreciated.
Thank you.
Certain characters have special meaning when used on the command line. For example, if your URL there are several & characters, which tells the shell to run the command before it, and run the next command without waiting for the first one to finish, basally terminating the URL early, and running several other commands from the rest of the URL.
You can avoid these issues by enclosing the URL in single quotes like this, which will prevent the shell from parsing special characters or variables.
wget 'YOUR_URL_HERE'

STDERR output in asterisk cli

How can i see the output to STDERR in asterisk CLI? I found that the stderr output is visible in the original asterisk terminal but cannot be seen in the cli which is obtained by asterisk -cvvvvvvvvvr. I want to see the error message of my perl agi script (warn "text") .
You can't see it.
Reason: stderror sended to linux stderror handler of asterisk process. When you connect to asterisk console, you have other proccess which have other stderror handler.
So if you want see errors, you need setup your asterisk startup script to store that errors in some file. Or edit default script /usr/sbin/safe_asterisk to suite your need.
Actualy if you read AGI specification you can see,that your script have send error messages to stdout,preferable using WARNING agi function. That can be archived by redirecting stderror to stdout in script or by writing special handler/wrapper.

How to send stderr in email shell script (ash)

I wrote a shell script that I use under ash, and I redirect stderr and stdout to a log file. I would like that log file to be emailed to me only if stderr is not empty.
I tried:
exec >mylog.log 2>&1
# Perform various find commands
if [TEST_IF_STDERR_NOT_EMPTY]; then
/usr/bin/mail -s "mylog" email#mydomain.com < mylog.log
fi
My question is twofold:
1- I get a -sh: /usr/bin/mail: not found error. It seems that the mail command doesn't exist under ash (or at least under my linux box, which is a Synology NAS), what would be the alternative? Worst case, perl is available, but I would prefer to use standard sh commands.
2- How to I test that stderr is not empty?
Thanks
How to check if file is empty in bash
As for the first question, in your code you are calling mail but lower in the post you are calling email. Check your code and make sure it is mail.
Use which mail to get the full path. Maybe it is not installed in /usr/bin/.
Use find to locate mail.
If you can go to another shell, run it and then execute which mail to get the full path of mail in case the path is set up in the alternative shells.

Start a groovy script directly from its url

I have a script that is available on the web, and I want to run it directly by entering its url, instead of downloading it and running later. Is there a way to do it ?
If you want to run a groovy script from a URL from the command line, you can do the following:
groovy -e 'evaluate( new URL( "http://yoururl.com/yourscript.groovy" ).text )'
Edit
Since Groovy 1.8.3, it is possible to do:
groovy http://myserver/myScript.groovy
Obviously care must be taken with doing this either way... Running stuff straight off the internet is never best advised ;-)