w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Not getting UUID from diskutil on OSX
The only way I've been able to find involves a somewhat poorly documented feature of the hfs.util. Run the diskutil command and then copy/remember/save the Device Identifier: diskutil info /Volumes/my_drive_label | grep "Device Identifier" You can use the hfs.util with the Device Identifier (replacing disk2s1 below) from diskutil to (re)generate a UUID for your volume: /System/Library/Filesystems/hfs.fs/hfs.util -s disk2s1 Keep in mind this won't work for every volume, if the volume is not an HFS drive than it may not work, and other Filesystem/*.fs/*.util commands may not have a -s verb to generate UUIDs. UPDATE In Yosemite and after the -s flag has been disabled at the source level. I haven't been able to find a pre-modified version of hfs.util, but you can do it yourself using

Categories : Misc

Capture output of a bash command, parse it and store into different bash variables
You can use awk and bash arrays: arr=( $(awk -F ':' '$1 == "inet addr"{sub(/ .*/, "", $2); print $2}' < <(ifconfig)) ) Then you can do: read IPETH0 IPLO <<< ${arr[@]}

Categories : Linux

After new partition gets created insert partition info in another table through trigger
You can do it with DDL Trigers. Check out this link One important note from the author you should consider adding a partition is not DDL if Oracle decides to do it internally, it’s only DDL if it’s an end-user statement Implicit partition creation is a new feature of 11g and it reffers to the interval partition option.

Categories : Oracle

Hoare partition : is this implementation more/less efficient than the standard partition algorithm?
I always prefer the standard Hoare's implementation. If you look at it, it is not very intuitive, but it has a visible advantage: Less number of swaps. While your implementation effectively always does exactly N comparisons and N swaps, the Hoare's implementation does only N comparisons, but it does not swap anything if it is not needed. The difference is significant in some scenarios. At first in a case you use environment where swaps or assignment of variables/objects is a costy operation. For example if you use C/C++ with arrays of objects. Another typical examples where Hoare's partition implementation performs better if when many of the items in your array are of the same value or when the array is almost sorted and needs just to swap a few items. In that cases Hoare's version perfor

Categories : Matlab

Finding a malicious script on my webserver with bash
You could use inotify to get informed when your html files are changed and only run your script in that case. When you know that your files get modified (e.g. by above inotify) you can use the proc system of the processes (or something like lsof) to find out which process has opened the modified file.

Categories : Bash

Finding files in list using bash array loop
First, I would just assume that all the file-names are supplied on standard input. E.g., if the file names.txt contains the file-names and check.sh is the script, you can invoke it like cat names.txt | ./script.sh to obtain the desired behaviour (i.e., using the file-names from names.txt). Second, inside script.sh you can loop as follows over all lines of the standard input while read line do ... # do your checks on $line here done Edit: I adapted my answer to use standard input instead of command line arguments, due to the problem indicated by @rici.

Categories : Bash

finding duplicates in a field and printing them in unix bash
Update: The question has been changed significantly. Formerly, when answering this, the input file should look like: apple apple banana orange apple orange banana orange apple ... However, the solution will work anyway, but might be a little bit too complicated for this special use case. The following awk script will do the job: awk '{i=1;while(i <= NF){a[$(i++)]++}}END{for(i in a){if(a[i]>1){print i,a[i]}}}' your.file Output: apple 3 orange 2 It is more understandable in a form like this: #!/usr/bin/awk { i=1; # iterate through every field while(i <= NF) { a[$(i++)]++; # count occurrences of every field } } # after all input lines have been read ... END { for(i in a) { # ... print those fields which occurred more than 1 time if(a[i] > 1) {

Categories : Bash

Bash finding files in subdirectories and move them into a new folder
Try this command: #!/bin/bash find Dir1 -mindepth 1 -type f -name '*.RAW' | while read -r FILE; do DIRNAME=${FILE%/*} mkdir -p "$DIRNAME/RAW" && mv "$FILE" "$DIRNAME/RAW/" done

Categories : Bash

MySQL table Partition with FLOOR function (partition function not allowed)?
MySQL documents the partitioning functions here. The floor() function appears to have some special considerations. In this case, I think the issue might be that the division is returning a float/double result rather than a decimal result. This is easily fixed in your case because you do not need to do the division: CREATE TABLE `fact_events` ( `event_key` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `event_type_key` tinyint(3) unsigned NOT NULL, `analytic_file_id` bigint(20) unsigned NOT NULL, `sdk_session_id` bigint(20) unsigned NOT NULL, `virtual_button_create_id` bigint(20) unsigned NOT NULL, PRIMARY KEY (`event_key`), KEY `idx_events_event_type` (`event_type_key`) ) PARTITION BY RANGE(event_key) ( PARTITION p0 VALUES LESS THAN (0), PARTITION

Categories : Mysql

Bash, printing after output on new
Depends what you consider 'normal'. All programs are set of 0 and 1 arrange in special order. Apparently, 'G' and '1' in base64 are 'enter' and 'end of line' respectively. To confirm this just change the sequence to any other.

Categories : Bash

Sort output in bash
You can simply add sort to end of your loop to sort the outputs. #!/bin/bash for i in `find . ! -path "*/target/*" -type f -name pom.xml` do grep -q 'IC_Maven_JEE_Parent|IC_Maven_Parent' $i if [ "$?" -eq 0 ]; then echo $(grep -o 'IC_Maven_JEE_Parent|IC_Maven_Paren' $i) $(echo -e 'setns x=http://maven.apache.org/POM/4.0.0 cat /x:project/x:parent/x:version/text()' | xmllint --shell $i | grep -v /) $i fi done | sort

Categories : Linux

Finding the most probable value from the MCMC sampler output
Edit: As Ahmed Fasih points out, I misread the question. His advice in the comment of the question is the way to do it =) That functionality is built into PyMC. The class MAP in the main pymc namespace accepts an array of pymc variables (or a Model class), and exposes a fitmethod. map = mc.MAP(model) #or [var1, var2, .. ] map.fit() then all the pymc variables will be set the the maximum aposterior.

Categories : Python

Bash non scrolling terminal output
Instead of printing whole lines (as with println or printing %n), write backspace characters () or bare carriage returns without linefeeds ( ) to move the cursor back in front of what you want to print over.

Categories : Java

Bash output to multiple variales
Answer: readarray -t interfaces < <(ip link | grep "<" | cut -d " " -f 2 | cut -d ":" -f 1 | grep -v lo) echo "${interfaces[0]}" # prints eth0 echo "${interfaces[1]}" # prints wlan0 And to loop over them use for: for curInterface in "${interfaces[@]}"; do echo "$curInterface" done But there are better ways to parse data: First of all, instead of grepping < character you can use -o flag. This will output all of the data on single lines. Then you simply need the second word without : character. This is very simple in pure bash: interfaces=() while read -r _ curInterface _; do interfaces+=("${curInterface%:}") done < <(ip -o link)

Categories : Bash

Parse MegaCLI output using BASH
When you say "ONLY BASH", do you really mean it? bash by itself is pretty powerless; it really depends on having a collection of non-builtin commands available to do anything nontrivial. Also, do you really just want the selected lines, or do you want to reformat the info at all? If you just want the lines (and maybe a little header info) and have egrep available, this is simple: MegaCLI -whateveroptions | egrep '^(Adapter|Product Name|RAID Level Size State|Number Of Drives|Physical Disk|Raw Size|Link Speed|Media Type|Drive Temperature):` If you really need 100% pure bash, you can do it with read, case, and echo: MegaCLI -whateveroptions | while read line; do case "$line" in Adapter:* | Product Name:* | RAID Level Size State:* | Number Of Drives:

Categories : Bash

Bash : echo binary output
Perhaps you need to use the -n option? echo -n "$SIZE" >> quota Or maybe you need the binary representation it but this is only limited to 8 bits or 255. echo -ne "$(printf '\x%x' 200)" >> quota Also make sure that you really need to use >> and not > as >> appends data to existing files, not overwrite it.

Categories : Bash

I'd like to grep the output of ifconfig in bash
use this: ONLINE=$(ifconfig | grep -cs 'status: active') cause without "$" what bash will return is the result of the command being successful or not and if it is successful it is always zero.

Categories : Bash

redirect the output into a new column in bash
This should help you - #!/bin/bash echo job_id run_id for i in {1..10} do wget www.abc.com?id=$i > sample.txt job_id_var=$(grep -E "jobId" sample.txt) # return 5 in first iteration, 10 in second run_id=$(grep -E "runid" sample.txt) # return 1001 in first iteration, 1002 in second echo "$job_id_var" "$run_id" >> outputfile done Explanation: Using echo $YOUR_VAR >> filename, you can append out the variables to files as you want them. I haven't formated this well, may be you could do that. I also saw you used >> to append the sample.txt - I suggest you overwrite using >, if it can solve your problem.

Categories : Bash

Suppress warning output in bash
Better give your exact code attempt and warnings in your original post, but if you try this one : { mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql; } 2>/dev/null or mysql_tzinfo_to_sql 2>/dev/null /usr/share/zoneinfo | mysql -u root mysql 2>/dev/null that should work.

Categories : Mysql

How to hide command output in bash
You can redirect stdout to /dev/null. yum install nano > /dev/null Or you can redirect both stdout and stderr, yum install nano &> /dev/null. But if the program has a quiet option, that's even better.

Categories : Bash

sed output blank in bash script
If you're going to use the flag -i, --in place, you don't have to redirect the output. The substitutions are performed in place, as expected. Yet, you can simplify your expression, doing: sed -i -e 's/abc-wxyz1/2222 ([0-9]+)/*/g' input.txt

Categories : Bash

Printing out wrong output in bash
You keep appending to the modified name. Use the original name instead. And that condition... origname="$name" while [ -f $name.contact ]; do name="$origname($count)" count=$(($count+1)) done

Categories : Bash

Parse SNMP output in Bash
Pipe through sed as shown below: $ snmpwalk -v2c -c community 192.168.122.15 .1.3.6.1.4.1.14823.2.2.1.4.1.2.1.39 | sed -r 's/.*.([0-9]+.[0-9]+.[0-9]+.[0-9]+) = .*: (.*)/1=2/g' 197.39.5.77="Android"

Categories : Linux

Bash recursive capturing of commands output
Use the dollar parenthesis syntax for recursively capturing command output: base=$(basename $(readlink link)) The issue with the back-ticks is that when the interpreter encounters the second back-tick, the interpreter thinks the back-tick closes the first command whereas what you want is to open a new command.

Categories : Linux

Pick a specific value in a program output (Bash)
Try grep in PCRE mode (-P), printing only the matched parts (-o), with a lookahead assertion: $ echo "Accuracy = 80% (24/30) (classification)" | grep -Po '[0-9]+(?=%)' 80 The regexp: [0-9] # match a digit + # one or more times (?=%) # assert that the digits are followed by a %

Categories : Linux

Check for ftp authentication output for bash script
The message below is probably going to stderr instead of stdout so you will need to capture the stderr output first: while true do if ( script 2>&1 |grep -q 'Authentication failed' ) then echo "authentication failed, sleeping for a while before trying again" sleep 60 else #everything worked, break out of the while loop break fi done

Categories : Linux

tail not providing output in bash script
Try this: phonenumber=$(tail -f /var/log/asterisk/messages | awk 'match($12, /[^0-9]91([0-9]{10})@default/, a) {print a[1]; exit}') Your version doesn't work because tail -f and awk are in an infinite loop. Adding exit to the awk script terminates the loop when the first phone number is found. awk exits immediately and its output is put into the variable, and tail -f gets a SIGPIPE signal when it tries to write the next line to the pipe, which causes it to exit.

Categories : Linux

explain bash variable assignement output
Because echo $test > test2 writes the output to a file named test2. this set of commands is does what you would expect: test="zut"; echo $test; test2=$test; echo "echo test " $test2

Categories : Bash

How do I retrieve the header when I want to look at grep output of something in bash?
With awk: command | awk 'NR==1||/bla/' Thanks to @doubleDown for pointing out that {print} is unnecessary since it is the default action. With perl: command | perl -ne 'print if $.==1 or /bla/' (If you need perl irregular expressions, perl is probably available :) )

Categories : Bash

How to avoid blackboxing function output in bash?
How are you executing the script, and what's calling main()? Bash scripts aren't like C programs and don't require a main() function. Bash will "remember" any functions it sees, but you actually need to call them directly from the script. Try this: # Start of script prompt() { read -p "This is an example prompt. [Y/n]" } prompt # End of script bash$ chmod +x script_name bash$ ./script_name

Categories : Bash

Change output path of program in bash
APPDATA=%CD%/certainfolderforportablestuff in bash should be APPDATA=$PWD/certainfolderforportablestuff And since you're just starting with bash I suggest that you place variables inside double quotes by default: APPDATA="$PWD/certainfolderforportablestuff"

Categories : Osx

Bash filtering output when receiving input
You'll need to not use while read, since read only processes "complete" lines, i.e. lines that end with LF. (Alternatively, read has an option -d delim which tells it to treat another delimiter as the end-of-line marker - in your case, this could be the question mark, or the : at the end of the prompt. However, I'll guess you can't use this in your particular case because you won't be able to predict when to use -d). Depending on what exactly your script is doing, you might be able to pipeline the entire tweaking, e.g. through sed, awk and the likes. For a more detailed answer, you'll need to post the innards of your current script.

Categories : Bash

Bash - output of command seems to be an integer but "[" complains
If the output of the ssh command is truly just an integer preceded by optional tabs, then you shouldn't need the sed command; the shell will strip the leading and/or trailing whitespace as unnecessary before using it as an operand for the -lt operator. if [ $(ssh -tti id_dsa headless@remoteserver.com "ps -auxwww | grep -c pipeline") -lt 3 ]; then It is possible that result of the ssh is not the same when you run it manually as when it runs in the shell. You might try saving it in a variable so you can output it before testing it in your script: result=$( ssh -tti id_dsa headless@remoteserver.com "ps -auxwww | grep -c pipeline" ) if [ $result -lt 3 ];

Categories : Bash

Why does power of two >62 in bash output negative values or zero?
Calculations are being made on signed 64 bit integers. Therefor 2^62 is in positive range of 64 bit signed integer 2^63 is lowest negative 64 bit signed integer as it is over highest positive 2^63-1 2^64 and greater results in overflow and 0 is displayed Python offers your better handling of large numbers than bash. $ python -c 'print 2**256' 115792089237316195423570985008687907853269984665640564039457584007913129639936

Categories : Bash

Checking output of multiple variables in bash
the test command allows compound statements. If you just want to check that each of the strings is non-empty: if [ -z "$LSIBATTSTATE" -o -z "$LSIBATT" -o -z "$LSIWB" -o -z "$ADAPZMM" ]; then [error stuff] fi If you want something a little bit more extensible, you could run an array or sum of result codes: Initialize RESULTS=() RESULTSUM=0 Update after each command RESULT=$? RESULTS[${#RESULTS[*]}]=$RESULT RESULTSUM=$(($RESULTSUM + $RESULT)) Then after they are all done: if [ $RESULTSUM -eq 0 ]; then [error stuff which can use $RESULTS array to know which command failed] fi

Categories : Linux

Batch Scripting - Finding OS Version information - Variable Output
Changed FOR /F "usebackq delims=: tokens=2" %%i IN (osname.txt) DO set vers=%%i To FOR /F "usebackq delims= tokens=2" %%i IN (osname.txt) DO set vers=%%i *Changed the : to a %space% after delims...

Categories : Windows

Get quota output from cyradm (cyrus) in a bash script
Hope you tried this -> while read userName;do echo $(cyradm -u cyrus -w my_cyrus_password localhost << sample lq user/$userName sample ) >> outfile done</home/myuser/tempfiles/tempnames.txt

Categories : Bash

How do you execute several bash functions in the background but wait for output?
For anyone else who comes along: Given the following: function par() { parallel sh -c ::: "sleep 1" "sleep 1" "sleep 1" } function seq() { sleep 1 sleep 1 sleep 1 } Timing both commands shows that the first function executes all at once while the second function waits for each command to be finished before moving on to the next: $ time par && time seq real 0m1.215s user 0m0.147s sys 0m0.085s real 0m3.028s user 0m0.011s sys 0m0.012s Happiness!

Categories : Bash

Sending output of 2 rsync commands in a bash script
You may want to put both commands inside the command expansion: rfiles=$(rsync -rvlpogt /svntags/tags/ /var/www/html/ && rsync -rvlpogt /svnbranch/branches/ /var/www/html/)

Categories : Bash

bash: different sort output on files with identical first column
sort -t $' ' -k 1,1 Use $' ' to have the shell interpret as a tab since sort doesn't parse escape sequences. Use -k to tell it to only sort on the first field rather than the entire line. You might also want the -V flag if you want 2 to sort in between 0 and 10.

Categories : Bash



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.