shell

How do I listen for a response from shell command in android studio?

跟風遠走 提交于 2021-01-29 01:49:54
问题 In an android terminal emulator I can type the following commands: > su > echo $(</sys/class/power_supply/battery/charge_rate) and depending on how the phone is charging the output will be "None", "Normal" or "Turbo". I would like to be able to retrieve this output and store it as a string value in my program. So I've done a little bit of research into this and the code I came up with is as follows: String chargeRate = "None"; try { Runtime rt = Runtime.getRuntime(); Process process = rt.exec

How do I listen for a response from shell command in android studio?

僤鯓⒐⒋嵵緔 提交于 2021-01-29 01:46:39
问题 In an android terminal emulator I can type the following commands: > su > echo $(</sys/class/power_supply/battery/charge_rate) and depending on how the phone is charging the output will be "None", "Normal" or "Turbo". I would like to be able to retrieve this output and store it as a string value in my program. So I've done a little bit of research into this and the code I came up with is as follows: String chargeRate = "None"; try { Runtime rt = Runtime.getRuntime(); Process process = rt.exec

Let bash loop over unknown number of variables

半城伤御伤魂 提交于 2021-01-28 23:10:43
问题 I have a file where a bunch of variables are defined. It could be one, four or twenty. They have names such as ipt_rss and bhd_rss . Let's call these variables var_i Now, I'd like to let bash loop over these variables like this: for all i in var_i do command1 arg command2 arg $var_1 > /some/directory/$var_i.rss echo "Success finding $var_i" done How can I accomplish that? 回答1: If the variables all begin with a common prefix, you can iterate over all such variable names and use indirect

Delete all old files, but keep newest 4 files using ansible-playbook

倾然丶 夕夏残阳落幕 提交于 2021-01-28 22:14:16
问题 I would like to delete all old files, and keep newest 4 files. The output isn't what i expected. Even i use absent on file modules, but it doesn't delete the files. My files are here # ls -l /home/tomcat/backup total 0 -rw-r--r-- 1 root root 0 Mar 3 14:21 1 -rw-r--r-- 1 root root 0 Mar 3 14:21 2 -rw-r--r-- 1 root root 0 Mar 3 14:21 3 -rw-r--r-- 1 root root 0 Mar 3 14:21 4 -rw-r--r-- 1 root root 0 Mar 3 14:21 5 -rw-r--r-- 1 root root 0 Mar 3 14:21 6 -rw-r--r-- 1 root root 0 Mar 3 14:21 as -rw

How to increase value of a text variable in a file

瘦欲@ 提交于 2021-01-28 21:24:55
问题 file1.text contains below data. VARIABLE=00 RATE=14 PRICE=100 I need to increment value by 1 only for below whenever I want. VARIABLE=00 file name: file1.txt output should be incremented by 1 every time. output will be like below VARIABLE=01 in next run VARIABLE=02 and so on.... 回答1: Could you please try following, written and tested with shown samples in GNU awk . awk 'BEGIN{FS=OFS="="} /^VARIABLE/{$NF=sprintf("%02d",$NF+1)} 1' Input_file > temp && mv temp Input_file Explanation: Adding

sed replace positional match of unknown string divided by user-defined separator

瘦欲@ 提交于 2021-01-28 20:41:27
问题 Want to rename the (known) 3th folder within a (unknown) file path from a string, when positioned on 3th level while separator is / Need a one-liner explicitly for sed. Because i later want use it for tar --transform=EXPRESSION string="/db/foo/db/bar/db/folder" echo -e "$string" | sed 's,db,databases,' sed replace "db" only on 3th level expected result /db/foo/databases/bar/db/folder 回答1: You could use a capturing group to capture /db/foo/ and then match db . Then use use the first caputring

When running an ansible playbook via a shell script in Jenkins pipeline, the echo output is buffered and does not show in real time

吃可爱长大的小学妹 提交于 2021-01-28 20:00:53
问题 So below I have attached my pipeline code for Jenkins. The runansible.sh script takes in the parameters given and then proceeds to run an ansible playbook based on the paramMode value. When kicking off the shell script in a terminal I get realtime output of the ansible playbook running, but when using the Jenkins pipeline I just get the loading cogwheel during the echo stage. I do not get any echo output until the whole playbook has completed and then it spits it out all at once. I need to be

Conditional redirection appending / overwriting

我的梦境 提交于 2021-01-28 19:33:57
问题 I have a condition, depending on which I want to either append or overwrite some file like this: if [ "${CONDITION}" -eq 1 ]; then echo "writing some info" echo "${INFO1}" > "${FILE1}" echo "${INFO2}" > "{$FILE2}" ... else echo "Appending some info" echo "${INFO1}" >> "${FILE1}" echo "${INFO2}" >> "{$FILE2}" ... fi The thing is that if and else blocks are relatively big (20 lines each) and are essentially identical except the redirection difference. This makes me feel really bad indeed. How

Current charset of the windows script host

落花浮王杯 提交于 2021-01-28 19:32:02
问题 I write script (js or vbs, not significant) with Windows Script Host that creating .bat file. I want to convert ANSI string to OEM with ADODB.Stream I may get current OEM code page with Split(CreateObject("WScript.Shell").Exec("cmd /c chcp").StdOut.ReadAll, ":")(1) and then convent it to charset with http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx. How I may get the current ANSI(script) charset? 回答1: The Windows codepage can be determined via WMI, by reading

How do I pass Shell parameters to Perl script?

时光怂恿深爱的人放手 提交于 2021-01-28 19:07:21
问题 I am trying to find dates with in a certain format, I have done it before with perl( strftime ), but that time I mentioned a static time, this time i need a variable $CURRENT_DAY here. Below is the issue, when equate the CURRENT_DAY by using DAYHOUR=86400 and an integer, the variable is giving the right time, but once I put $CURRENT_DAY variable in the statement, the date would not decrease. $ DAYHOUR=86400 $ DAY=1 $ CURRENT_DAY=`echo $(($DAYHOUR*$DAY))` $ DD=`perl -e 'use POSIX; print