Posts

Showing posts with the label shell

Shell script: while variable concatenation

Shell script: while variable concatenation This is my straightforward function: generate_post_data() { cat <<-EOF {"stringData": {}} EOF } This is my other function: generate_curl_body() { template=$(generate_post_data $secret_id) echo "$template" echo "$KVS_VARIABLES" | while read -r key value do template=$(echo "$template" | jq ".stringData += { "$key" : "$value" }") echo $template done } The output is: #Before while -> {"stringData": {}} #1 iteration -> { "stringData": { "VAR1": "VAL1" } } #2 iteration -> { "stringData": { "VAR1": "VAL1", "VAR2": "VAL2" } } #3 iteration -> { "stringData": { "VAR1": "VAL1", "VAR2": "VAL2", "VAR3": "VAL3" } } #After while -> {"stringData": {}} Why template variable is not ...

Find connected bluetooth device name using adb? [duplicate]

Find connected bluetooth device name using adb? [duplicate] This question already has an answer here: Is there any way to find the connected BT device name using adb shell? My phone is rooted and I'm building a tasker profile which flashes the BT device name when connected. This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. 1 Answer 1 You want to know your Bluetooth profile name or connected/paired device bluetooth name? Both names you can get by below command: adb shell dumpsys bluetooth_manager The above command will give the output like this: Bluetooth Status enabled: true state: STATE_ON address: A4:70:D6:80:56:3E name: Moto G (4) (This is your device name) time since enabled: 00:03:29.979 Bonded devices: C0:EE:FB:DA:70:6E [BR/EDR] Oneplus3 (This is connected device name) ................

Shell Jenkins job reading text from file with variables

Shell Jenkins job reading text from file with variables I am implementing Jenkins job in bash shell script. Jenkins jobs is using the variable AS_OF_DATE which can be used as input for users. AS_OF_DATE I also have some files on zone with text that I grep during the execution of this jenkins job. So user will start the jobs and given parameters is: AS_OF_DATE: "20180331" AS_OF_DATE: "20180331" Then during the job I grep some text from test.txt file. test.txt TEXT_FROM_FILE="This is my text, where i used ${AS_OF_DATE}" And when I do the echo of $TEXT_FROM_FILE , variable $AS_OF_DATE is not changed with the date that user added. $TEXT_FROM_FILE $AS_OF_DATE My outcome is: "This is my text, where i used ${AS_OF_DATE}" What it should be: "This is my text, where i used 20180331" "This is my text, where i used 20180331" I assume that I am not declaring the variable inside the file correctly, so my question is hot to correctly spe...

jq shell script: aggregate iteration content into json body

jq shell script: aggregate iteration content into json body I'm creating a shell script. I need to create a curl json body according the a key-value list content. This content is splitted by way of a awk which generate a two column table: key-value awk KVS_VARIABLES=$(awk -F= '!($1 && $2 && NF==2) { print "File failed validation on line " NR | "cat 1>&2"; next } { print $1, $2 }' $f) Example output: VAR1 VAL1 VAR2 VAL2 VAR3 VAL3 So, this table is iterated on a while iteration and each key and value are splitted: key value echo "$KVS_VARIABLES" | while read -r kv do key=$(echo $kv | awk '{print $1}') value=$(echo $kv | awk '{print $2}') done So, I need some way to aggregate this content into a json document in order to send it out using curl : curl curl -k -X PUT -d @- -H "Authorization: Bearer $TOKEN" -H "Accept: application/json" -H "Content-Type: applica...

Shell script internally call another shell script and doesnot return the ouput to main script when i use the external table

Shell script internally call another shell script and doesnot return the ouput to main script when i use the external table My main script api_call.sh internally calls config.sh and should pass the parameter value to the main script. The script works fine when I execute it in Linux. But when I queries through external table the second script does not return the output to the main script. Can anyone please tell me. Do I need to specify the location when I call the second script when I queried via external table..? And how can I return the value from the second script to the first one. Script1: apicall.sh export SourceName FileName . ./config.sh "$SourceName" "$FileName" get the application type from the config file to the main script v_application_type=$application_type Script2: config.sh while : do case $1 in xxx) application_type=application/json ...

Pixelbook CromeOS Secured Shell App sftp mount fails

Pixelbook CromeOS Secured Shell App sftp mount fails My new Pixelbook i7 arrived and I was trying to install Android Studio. I followed the steps on this page: https://developer.android.com/topic/arc/studio I got to step 6 under "Mount Linux file". On step 5 I replaced the hostname with the IP address, clicked SFTP Mount and got the following. (I replaced part of the IP address with **). Welcome to Secure Shell App version 0.8.43. Answers to Frequently Asked Questions: ... (ctrl+click on links to open) [Pro Tip] Use 'Open as Window' or 'Fullscreen' to prevent Ctrl-W from closing your terminal! [Pro Tip] See .... for more information. ChangeLog/release notes: ... Random Pro Tip #6: Color your output/prompt using basic 16 colors & 256 colors & full 24-bit colors: http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html Connecting to cfan@100.***.**.198... Loading NaCl plugin... done. ssh: connect to host 100.***.**.198 port 22: Connection refused failed! :( Wh...

Execute several command in linux shell file [closed]

Execute several command in linux shell file [closed] I only can get the desire output when I run the command one by one. How can I combine all the command in a shell script and get the desired output? //insert timestamp column $ vmstat -n 5 | (while read; do echo "$(date +%Y-%m-%d.%H:%M:%S) $REPLY"; done)> vm.txt //remove 1st & 2nd row $ sed '1,2d' vm.txt > vm2.txt //convert text file to csv $ sed 's/^ *//;s/ */,/g' vm2.txt > vm2.csv //insert column name $ echo $'datetime, r, b, swpd, free, buff, cache, si, so, bi, bo, in, cs, us, sy, id, wa, st' | cat - vm2.csv> chart.csv $ psql -p 5432 -U postgres -c "copy vmstat FROM '/root/report/chart.csv' delimiter '|' csv header" Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. ...

jenkins build failure shell command permission denied

jenkins build failure shell command permission denied I am trying to run shell build command on mac but I get permission denied for e.g. ls /Users/... command. permission denied ls /Users/... I see whoami is jenkins , which is different for my uesr login? whoami jenkins I read online I need to run chmod for jenkins user, how do I do that? I changed file permission using chmod 777? Do I need to change jenkins user? The ... in your ls command is important for us to see, don't shorten it. Also "run chmod for jenkins user" means nothing to me. chmod what file/directory? You changed file permissions, on what? – Kusalananda Jun 19 '16 at 8:45 ... ls chmod 3 Answers 3 Maybe you have a problem that jenkins is not a full user. Try this: j...

Retrieve value from command output

Retrieve value from command output I'm looking for a method which would allow me to retrieve a value from a command output. An example might be retrieving the IP address from an ipconfig output, or the encryption status from a manage-bde -status output. It's essentially the value after the colon ":" . I tried playing with the findstr options, but I could not retrieve "just" the value. In the ipconfig example, I want only the IP address, and in the "manage-bde" example, I want only the word "protection off". The above two commands are only examples. ipconfig manage-bde -status In addition, I need to figure out a method to perform a foreach in the event there are more than one IP/Nic, or more than one volume. foreach I could be either just one command, or output the results to a file, and then run something against the file. The answer to the basic question here is assign it to a variable. However you are look...

Are there any command-line browsers which can execute javascript on the DOM and also execute javascript on that DOM (interactive console)?

Are there any command-line browsers which can execute javascript on the DOM and also execute javascript on that DOM (interactive console)? I'm looking for a command line browser or web browser command-line interface (headless/gui-less option) that can be run in a terminal (preferably linux/bash) which loads the DOM and received javascript, and then allows for console execution of javascript on the loaded DOM. The goal is to operate on the DOM through the console. I'm not looking for CLI-based page downloading, stand-alone js execution or load a js page from CLI. Links and Lynx both explicitly do not support javascript (at least according to those wikipedia pages). Are there any command-line-based or very-very-lightweight we browsers that I could use [preferably through linux/bash (Ubuntu/Mac OS X)] to operate on the browser DOM with javascript support using an interactive console or locally-sourced javascript code? Could you append a <script> ...

Find matching pattern between columns and count for each distinct element in one column

Find matching pattern between columns and count for each distinct element in one column I have a tab delimited file with around 70 million rows like the following; chr1:25851453-25869713W:6655:4522:4234:2258:2508:S 6655 chr1:25851453-25869713W:6655:4523:4234:2258:2508:A 6655 chr1:25851453-25869713W:0000:4524:4234:2258:2508:S 6655 chr1:25851453-25869713W:6655:4525:4234:2258:2508:S 6655 chr1:26235471-26237662W:6663:124:1864:311:455:S 6663 chr1:26235471-26237662W:6663:125:1864:311:455:S 6663 I am trying to report for each distinct element in column 2, how many times the pattern after the second ":" in column 1 matches the pattern in column 2. So something like this for the above example; 6655 matches 3 6655 mismatches 1 6663 matches 2 6663 mismatches 0 (to be specific there are 15559 distinct values in column 2) Thanks! What have you tried so far? Could you post some code you've done? – matov...