How to use BroadcasetIntent() function in Monkeyrunner - monkeyrunner

Can anyone let me know how to use device.broadcastIntent function for the create contact using python script

device.broadcastIntent('android.intent.action.INSERT',
'vnd.android.cursor.dir/contact', {'name':'user1501488', 'phone':'123-15489'})
For shell command try this
device.shell("am start -a android.intent.action.INSERT
-t vnd.android.cursor.dir/contact -e name 'user1501488' -e phone 123-15489")

Related

sending data to telegraf from windows git bash

How exactly can I send data to telegraf from windows command prompt / git bash?
I'm trying to send data in unix bash to telegraf.
In bash I do:
echo -e "my_db,owner=me,field=value" | nc -u4 -w1 my.telefra.host.com 1231;
You can use telegraf exec input plugin.
It allows you to execute any sort of command, including powershell, cmd, git bash etc. For instance, if I want to run powershell command,
commands = ["powershell -command <command>"]
Same can be done for git bash,
commands = ["<path>\bash.exe <command>"]

Execute a terminal command which requires user input

How can I execute a system command that normally requires user interaction? For example, I would like to run:
system("ssh-keygen")
At the terminal prompt, it looks like this:
iMac-2:~ admin$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/admin/.ssh/id_rsa):
In RStudio, this command causes the application to hang.
I've tried the options wait=FALSE, AND invisible=FALSE, but they don't seem to help.
R: Using wait=FALSE in system() with multiline commands
`system()` interactive .exe/binary from R/Rgui
Well.
There are some commands who let you to put the parameters in command line:
For example:
ssh-keygen
If you run: ssh-keygen --help you could find something like this:
ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]
It says you could specify the parameters in command line.
In my case I've tested with:
ssh-keygen -f /tmp/id_rsa -P ""
And I don't need to interact with the program.
Like another example like adduser command, you could try with:
echo PASSWORD | passwd USERNAME --stdin

Running a script according to shebang line

I've got a script on my computer named test.py. What I've been doing so far to run the program is type python test.py into the terminal.
Is there a command on Unix operating systems that doesn't require the user to specify the program he/she uses to run the script but that will instead run the script using whichever program the shebang line is pointing to?
For example, I'm looking for a command that would let me type some_command test.txtinto the terminal, and if the first line of test.txt is #!/usr/bin/python, the script would be interpreted as a python script, but if the first line is #!/path/to/javascript/interpreter, the the script would be interpreted as javascript.
This is the default behavior of the terminal (or just executing a file in general) all you have to do is make the script executable with
chmod u+x test.txt
Then (assuming text.txt is in your current directory) every time you type
./text.txt
It will look at the sh-bang line and use the program there to run text.txt.
If you really want to duplicate built-in functionality, try this.
#!/bin/sh
x=$1
shift
p=$(sed -n 's/^#!//p;q' "$x" | grep .) && exec $p "$#"
exec "$x" "$#"
echo "$0: $x: No can do" >&2
Maybe call it start to remind you of the similarly useful Windows command.

Unix mailx html mail not working

Following html mail using mailx command is working from shell terminal, but the same command is not working from shell script.
mailx -s "$(echo -e "${sub} TRP OF ${system} \nContent-Type: text/html")" example#gmail.com < TRP.html
I guess it is some small escape character error, but not sure what it is.
Can any one help here?
Perhaps your vars sub / system are only known in your current environment.
When your sript is called mymail, try
. mymail
(Start with a dot),
or first export your vars.
When these suggestions fail, debug:
use set -x or temporary put an "echo -e" in front of your line.

Whats the difference between running a shell script as ./script.sh and sh script.sh

I have a script that looks like this
#!/bin/bash
function something() {
echo "hello world!!"
}
something | tee logfile
I have set the execute permission on this file and when I try running the file like this
$./script.sh
it runs perfectly fine, but when I run it on the command line like this
$sh script.sh
It throws up an error. Why does this happen and what are the ways in which I can fix this.
Running it as ./script.sh will make the kernel read the first line (the shebang), and then invoke bash to interpret the script. Running it as sh script.sh uses whatever shell your system defaults sh to (on Ubuntu this is Dash, which is sh-compatible, but doesn't support some of the extra features of Bash).
You can fix it by invoking it as bash script.sh, or if it's your machine you can change /bin/sh to be bash and not whatever it is currently (usually just by symlinking it - rm /bin/sh && ln -s /bin/bash /bin/sh). Or you can just use ./script.sh instead if that's already working ;)
If your shell is indeed dash and you want to modify the script to be compatible, https://wiki.ubuntu.com/DashAsBinSh has a helpful guide to the differences. In your sample it looks like you'd just have to remove the function keyword.
if your script is at your present working directory and you issue ./script.sh, the kernel will read the shebang (first line) and execute the shell interpreter that is defined. you can also call your script.sh by specifying the path of the interpreter eg
/bin/bash myscript.sh
/bin/sh myscript.sh
/bin/ksh myscript.sh etc
By the way, you can also put your shebang like this (if you don't want to specify full path)
#!/usr/bin/env sh
sh script.sh forces the script to be executed within the sh - shell.
while simply starting it from command line uses the shell-environemnt you're in.
Please post the error message for further answers.
Random though on what the error may be:
path specified in first line /bin/bash is wrong -- maybe bash is not installed?

Resources