Menu
  • HOME
  • TAGS

How to do the expansion of variable in shell script? [duplicate]

linux,bash,shell,unix,ksh

Using bash -c: newvar="$(bash -c "echo $var")" Using eval: newvar="$(eval "echo $var")" Example: #!/bin/bash var='$PATH' echo "$var" #This will show that $var contains the string $PATH literally #Using bash -c newvar="$(bash -c "echo "$var"")" echo "$newvar" #using eval newvar="$(eval "echo "$var"")" echo "$newvar" It will print the environment variable paths...

linux - running a process and tailing a file simultaneously

bash,shell,tail

I would simply start the tail in background and the python process in foreground. When the python process finishes you can kill the tail, like this: #!/bin/bash touch /tmp/out # Make sure that the file exists tail -f /tmp/out & pid=$! python test.py kill "$pid" ...

Deleting upto a line

bash,perl,shell,sed,scripting

Try this: grep -oE '[0-9.-]+$' file or awk '{print $NF}' file ...

Python subprocess.call doesn't work without shell=True

python,shell

Don't quote the arguments, the args are passed directly to the process without using the shell when shell=False: subprocess.call(["cscope", "-d", "-L0","temp"]) You should use check_call: from subprocess import check_call check_call(["cscope", "-d", "-L0", "temp"]) ...

Piping echo into sendmail in rc.local fails

linux,shell,email,sendmail,boot

Problem in using bash/zsh vs /bin/sh Bash and Zsh have builtin echo with option -e, but a system /bin/echo - not. Compare: /bin/echo -e "TO:[email protected] \nSUBJECT:System Booted \n\nBeware I live! \n" echo -e "TO:[email protected] \nSUBJECT:System Booted \n\nBeware I live! \n" You may use script like this: #!/bin/sh sendmail -t -vs...

how to deletes line from a text file that are taken from another file [duplicate]

shell,awk,sed,grep,sh

Something like this with grep: grep -vxf lines.txt data.txt > no_dupplicate_lines.txt Sample: AMD$ cat lines.txt Line2 Line4 AMD$ cat data.txt Line1 Line2 Line3 Line4 Line5 AMD$ grep -vxf lines.txt data.txt Line1 Line3 Line5 Print the lines that are not matching (-v) the exact lines (-x) from the file lines.txt (-f...

How to find out the user of parent shell inside a child shell?

linux,bash,shell

You can use the $PPID variable to assist you along with a command or two: #!/bin/bash USER=`ps u -p $PPID | awk '{print $1}'|tail -1` echo $USER ...

Why can I view some Unix executable files in Mac OS X and not others?

git,bash,shell,unix,binary

Executable files may be scripts (in which case you can read the text), or binaries (which are ELF formatted machine code). Your shell script is a script; git is an ELF binary. You can use the file command to see more detail. For example, on my nearest Linux system: $...

Expand passed arguments before printing with puts to virtual server

shell,tcl,expect

As Etan Reisner pointed use double quotes in the puts command instead of braces, so that it will get replaced. puts ${file_id} " root_image=node-${env(os1)} if {[string first r ${env(os1)}] == 0} { create_node_byid 1 [string range ${env(os1)} 0 4]-64 } else { create_node_byid 1 [string range ${env(os1)} 0 5]-64 }...

display.im6: no decode delegate for this image format `/tmp/magick-KFcbfWUi'

linux,r,bash,shell,csv

See docs.ggplot2.org/0.9.3.1/geom_bar.html. It expects the mapping first, then the data. And you don't actually have to specify df for the data, because it's already been captured in g. And I think you need to specify stat='identity' if you want to specify a y aesthetic....

How do I write a shell script to issue commands and see the output on the screen

bash,shell

You could do this ... #!/bin/sh set -x cd /WORKING_DIRECTORY make clean make mrproper make VARIANT_DEFCONFIG=msm8974_sec_hlte_spr_defconfig msm8974_sec_defconfig SELINUX_DEFCONFIG=selinux_defconfig make ...

launch several scripts located in subdirectories

linux,bash,shell

Try doing it using find and for: for file in `find . -type f -name "*.sh"`; do sh $file; done Use can also store it in array and do it: array=($(find . -type f -name "*.sh")) for file in ${array[@]};do sh $file; done ...

how to spy on linux binaries for testing of shell scripts

linux,bash,shell,testing,spy

Just an idea, I didn't see this anywhere but: Unless you're using full paths to invoke those binaries, you could create mocks of those libraries, e.g., in your projects bin/ directory and make that directory be the first in your $PATH. export PATH="$PWD/bin:$PATH" To mock grep, for example, you could...

ShellExecute doesnt work if some parameters are just int type

c#,windows,shell,interop

You need to dig into the Windows SDK headers to see how large the type is. For example, for a 64 bit process, sizeof(HWND) is 8 in C++ and sizeof(int) is 4 in C# therefore if you use int to store HWND, you are corrupting memory. Same for HKEY, LPITEMIDLIST,...

Calling find more than once on the same folder tree

linux,bash,shell,unix,find

Try this: find . -mmin +35 -or -mmin -25 find supports several logical operators (-and, -or, -not). See the OPERATORS section of the man pages for more details. ==================== EDIT: In response to the question about processing the two matches differently, I do not know of a way to do...

Group of data in shell language

linux,bash,shell

In x="1 2 3" for i in $x what you are doing is for i in 1 2 3:. But in second case doing xm=`cat $x` ym=`cat $y` This might lead to error saying No such file or directory is the echo $x and echo $y file does not exit....

File Handling and making directories to match in bash

bash,shell,sorting,matching,file-handling

#!/bin/bash # If there are no files match File_*.*.txt # replace File_*.*.txt by empty string shopt -s nullglob for i in File_*.*.txt; do echo "processing file $i" IFS="_." read foo num1 num2 foo <<< "$i" printf -v dir1 "Dir_%03d" "$num1" printf -v dir2 "Dir_%03d" "$num2" mkdir -pv "$dir1" "$dir2" cp...

How to find average and maximum in an interval using Shell [closed]

linux,bash,shell,unix,awk

Please make a search before you ask any question many posts are already there You can try something like below, modify accordingly Input [[email protected] tmp]$ cat input.txt 1 3 2 5 3 4 4 3 5 2 6 1 7 3 8 3 9 4 10 2 11 2 12...

Bash - How to discriminate control operator from metacharacter?

bash,shell

According to the bash manual, an operator is: A control operator or a redirection operator. See Redirections, for a list of redirection operators. Operators contain at least one unquoted metacharacter. The metacharacter is basically any character that cannot be part of a word. Definition of word: A sequence of characters...

Why does `su` not work in Jenkins?

shell,jenkins,su

su doesn't enter an interactive session when in a non-interactive session the way it does in an interactive session. In a shell script you get to run a single command in the su context su <user> <command>....

Escape sequence not working in python script run from a shell script

python,bash,shell

This worked: eval python pgm32.py $args More details on Setting an argument with bash Thanks @Barmar....

Unexpected concatenation of shell variables

shell

You should use a subshell to put the output of the command in mc, not a comma that executes the command and writes its output to stdout after mc has been assigned something and before you write mc to stdout: #!/bin/sh mc=XX:XX:XX:XX$(dd bs=1 count=2 if=/dev/random 2>/dev/null |hexdump -v -e '/1...

Error while executing lsof from bash script

linux,bash,shell,scripting

You have additional spaces at the declaration of IS_RUNNING. Try IS_RUNNING="$(lsof...)" ...

How to extract single-/multiline regex-matching items from an unpredictably formatted file and put each one in a single line into output file?

linux,shell,unix,replace,grep

Assuming that your document is well-formed, i.e. <b> opening tags always match with a </b> closing tag, then this may be what you need: sed '[email protected]<[/]\?b>@\n&\[email protected]' path/to/input.txt | awk 'BEGIN {buf=""} /<b>/ {Y=1; buf=""} /<\/b>/ {Y=0; print buf"</b>"} Y {buf = buf$0} ' | tr -s ' ' Output: <b>data1</b>...

Redirect output from file to stdout

bash,shell,unix,stdout

Many tools interpret a - as stdin/stdout depending on the context of its usage. Though, this is not part of the shell and therefore depends on the program used. In your case the following could solve your problem: myprog -o - input_file ...

Reading from linux command line with Python

python,linux,shell,command-line

You need to read stdin from the python script. import sys data = sys.stdin.read() print 'Data from stdin -', data Sample run - $ date | python test.py Data from stdin - Wed Jun 17 11:59:43 PDT 2015 ...

Passing commands to subprocess in shell

bash,shell,vagrant,karaf

You can redirect commands to karaf like: ./sudo karaf < echo 'feature:install' But I wouldn't recommend you to do that. You see shell will pass the command imidiatelly to karaf which isn't ready to accept those commands (I assume it takes some time for karaf to initialize itself) Instead you'd...

shell script cut from variables

bash,shell,shellcode

With GNU grep: grep -oP 'aaa&\K.*' file Output: 123 456 \K: ignore everything before pattern matching and ignore pattern itself From man grep: -o, --only-matching Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line. -P, --perl-regexp Interpret PATTERN as a...

Missing one condition to display a string

shell

The 'grep' command uses a regular expression to match text. Use a '^' before the expression, to match from the start of the line. So, you can change the line name=$(echo $hello | cut -d' ' -f9 | grep $1) to name=$(echo $hello | cut -d' ' -f9 | grep...

Shell script file, checks if text file is empty or not

shell,text-files

when i run my code i get the following ./todo.sh: line 25: syntax error near unexpected token else' ./todo.sh: line 25: else' You must use parentheses to define a shell function, but they have no part in calling one. A shell function is invoked just like any other command:...

Using AWK to parse fields with commas

regex,bash,shell,awk

I'm not willing to wade through your whole question (sorry, IMHO it's just too long with too much extraneous information) but it looks like you're trying to extract the individual fields from that "confile1" at the top of your question so maybe this is all the hint you need: $...

How to store command line arguments for future use?

bash,shell

Store all the arguments in an array: args=("[email protected]") Then print them as: printf "%s\n" "${args[@]}" ...

Shell script to loop over files with same names but different extensions

linux,bash,shell

anubhava's solution is excellent if, as they do in your example, the extensions sort into the right order. For the more general case, where sorting cannot be relied upon, we can specify the argument order explicitly: for f in *.ext1 do program "$f" "${f%.ext1}.ext2" done This will work even if...

Random password generate in shell script with one special character

bash,shell,unix,random,passwords

#! /bin/bash chars='@#$%&_+=' { </dev/urandom LC_ALL=C grep -ao '[A-Za-z0-9]' \ | head -n$((RANDOM % 8 + 9)) echo ${chars:$((RANDOM % ${#chars})):1} # Random special char. } \ | shuf \ | tr -d '\n' LC_ALL=C prevents characters like ř from appearing. grep -o outputs just the matching substring, i.e. a...

Allowing an executable to be terminated w/ ctrl+c in a shell script w/o exiting

bash,shell

The simplest way to do it is to trap the Ctrl+C signal to do nothing but pass the control to the shell script again. I tried the below code and it worked for me. Replace the sleep commands by the real commands you want to execute. #!/bin/bash #Trap the Ctrl+C...

Showing progress as shell script runs

shell,sh,snmp,net-snmp

This will print a dot to the screen every second. Add these lines just before the first snmpwalk command. while true; do echo -n . ; sleep 1 ; done & pid=$! #do time consuming tasks here Then to stop printing the dots, add this line just after the last...

AWK write to new column base on if else of other column

linux,bash,shell,awk,sed

You can use: awk -F, 'NR>1 {$0 = $0 FS (($4 >= 0.7) ? 1 : 0)} 1' test_file.csv ...

adb shell command from batch file

android,shell,adb

Just use the following line in your batch file: adb shell am instrumentation that will connect to the shell on the Android device and run the am command....

Use Xargs to wait for enter key

linux,bash,shell,xargs

Try something like this and just quit the editor when you finish editing each group of files? while IFS= read -r dir; do files=() while IFS= read -r -d '' xmlfile; do files+=("$xmlfile") done < <(find "$dir" -name "*.xml" -type f -print0) open -W "${files[@]}" done < <(awk '{print $2}'...

using sed to replace a line with back slashes in a shell script

regex,bash,shell,ssh,sed

You can use it with ssh and heredoc like this: ssh -t -t [email protected]<<'EOF' sed 's~out_prefix=orderid ^2\\\\d\\+ updatemtnotif/~out_prefix=orderid ^2\\\\d\\+ updatemtnotif_fr/~' ~/path/to/file exit EOF PS: It is important to quote the 'EOF' as shown....

Reading tab (\t) separated text from file in shell

bash,shell,text-files

In Bash you can do this: #!/bin/bash declare -a varA varB while IFS=$'\t' read -r num first second;do varA+=("$first") varB+=("$second") done <file echo ${varA[1]} ${varB[1]} You can access each element of varA array using index ${varA[$index]} or all of them at once with ${varA[@]}....

Using a command-line utility to perform the following map-updates

shell,command-line,awk,terminal

If order is not important, join and awk can do the job easily. $ join <(sort input.txt) <(sort mapping.txt) | awk -v OFS="|" '{for (i=3;i<NF;i++) print $2, $i OFS}' 103823054|001| 103823044|011| 103823044|012| 103823044|013| 103823064|011| 103823064|012| 103823064|013| ...

Why is Unix/Terminal faster than R?

r,bash,shell,unix,terminal

I'm not sure what operations you're talking about, but in general, more complex processing systems like R use more complex internal data structures to represent the data being manipulated, and constructing these data structures can be a big bottleneck, significantly slower than the simple lines, words, and characters that Unix...

How to check whether string matches that of a domain

regex,bash,shell

Bash regex doesn't have lookaround, you can use Perl Regex with grep: #!/bin/bash if grep -oP '^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,6}$' <<< "$1" >/dev/null 2>&1;then echo valid else echo invalid fi ...

Tmux breaks zsh aliases

bash,shell,alias,zsh

BASH_SOURCE cannot be used in .zshrc, because it is a bash-specific variable that isn't defined in zsh. You'll have to replace it with its zsh equivalent, found here.

Use Function From Earlier in Function Path

linux,shell,fish,aliases

The usual trick is to copy the function you want to override, and then invoke the copy from within the override: functions --copy ls saved_ls function ls saved_ls end You can't do this in an autoloading ls.fish file since it would result in an infinite loop, but you can do...

Passing GET variables to shell_exec in PHP

php,shell,get,mamp

GET-parameters are accessed via $_GET-variable. Notice the underscore before the "GET". http://php.net/manual/en/reserved.variables.get.php...

Identifying when a file is changed- Bash

bash,shell,unix

I would store the output of find, and if non-empty, echo the line break: found=$(find . -name "${myarray[i]}") if [[ -n $found ]]; then { echo "$found"; echo "<br>"; } >> "$tmp" fi ...

How to extract first letters of dashed separated words in a bash variable?

linux,string,bash,shell,variables

This isn't the shortest method, but it doesn't require any external processes. IFS=- read -a words <<< $MY_TEXT for word in "${words[@]}"; do MY_INITIALS+=${word:0:1}; done ...

Vagrant shell provisioning phpPgAdmin password

bash,shell,vagrant,vagrantfile,phppgadmin

First, you need to force htpasswd to read passwords from stdin. It can be done by supplying -i switch. Second, you need to pass a string into htpasswd stdin. This can be achieved in numerous ways. For example you can redirect stdout of echo into stdin of htpasswd. So resulting...

How to replace newlines/linebreaks with a single space, but only if they are inside of start/end regexes?

regex,linux,shell,unix,replace

You can do it using awk as: awk '/\[x/{f=1} {if(f)printf "%s",$0; else print $0;} /y\]/{print ""; f=0}' Output: [x data1 data2 data3 data4 y] [a data5 data 6 data7 data 8 b> [x data y] You can also simplify to: awk '/\[x/,/y\]/{ORS=""; if(/y\]/) ORS="\n";}{print}' Output: [x data1 data2 data3 data4...

Reading rsync source from file results in improper parsing of file names with white space

bash,shell,unix,scripting,rsync

Replace for JOB in `cat /tmp/jobs.txt`; do rsync -avvuh "$JOB" "$DESTINATION"; done by while read -r JOB; do rsync -avvuh "$JOB" "$DESTINATION" done < /tmp/jobs.txt ...

Fail Jenkins job when nosetests fail

python,shell,jenkins,continuous-integration

I suspect nosetests will return a non zero value on failure so you can set the shell to auto fail with set -e or any of the other options in here...

A python script that activates the virtualenv and then runs another python script?

python,windows,shell,command,virtualenv

You can activate your virtualenv and then start server using a bat file. Copy this script in to a file and save it with .bat extension (eg. runserver.bat) @echo off cmd /k "cd /d C:\Users\Admin\Desktop\venv\Scripts & activate & cd /d C:\Users\Admin\Desktop\helloworld & python manage.py runserver" Then you can just run...

Execute an shell program with node.js and pass params [closed]

node.js,shell,params

From: http://www.dzone.com/snippets/execute-unix-command-nodejs To execute shell commands: var sys = require('sys') var exec = require('child_process').exec; exec('command', function (error, stdout, stderr) {}); From: Run shell script with node.js (childProcess), To run a program bar.sh in your home folder with the argument 'foo': var foo = 'foo'; exec('~/bar.sh ' + foo, function (error,...

can't export a variable from execute shell in Jenkins to other project (with using properties file)

bash,shell,jenkins

Did you have a look to this solution? Jenkins: How to use a variable from a pre-build shell in the Maven "Goals and options" Using a shell pre-build step + the InjectEnv plugin, you should be able to solve your problem. Update from June 22nd, I add some screen copies....

Export database from a remote server into a specific folder on my computer

php,mysql,database,shell,command-line-interface

You can run mysqldump -h yourhostname -u youruser -p yourdatabasename > C:\your\file\path.sql -h connects you to the remote servers IP so you can dump the data locally, as long as your user has the correct privileges and you can connect remotely to your database server. However, you may need to...

Diffing two variables in a shell script

bash,shell

As pointed-out in the comments (hat tip to @anubhava), the OP isn't using bash for the actual script. The shebang must be #!/bin/bash to use the correct shell....

Nested For loop in makefile

shell,makefile,make

You shouldn't use at sign @ near the second for loop. @ should be used at the beginning of the whole shell command. The following worked for me: DIR= Sources \ Sources_2 all: @for entry in ${DIR}; \ do \ for i in $${entry}/*.c; \ do \ echo "Processing $${i}";...

How do I silence the HEAD of a curl request while using the silent flag?

bash,shell,curl,command-line,pipe

Try this: curl --silent "www.site.com" > file.txt ...

find numbers divisible by 3 in csv file using shell script

bash,shell,unix,awk

awk -F'|' '{for(i=1;i<=NF;i++)if(!($i%3))print $i}' file this awk one-liner shoud do. With your example, the cmd outputs: 3 6 9 ...

Run a command with sudo in bash shell

shell,cron,sudo

echo 'password' | sudo -S command

docker run local script without host volumes

database,shell,docker,docker-compose

The solutions I have found are: docker run tomdavidson/initdb bash -c "`cat initdb.sh`" and Set an ENV VAR equal to your script and set up your Docker image to run the script (of course one can ADD/COPY and use host volumes but that is not this question), for example: docker...

Sqoop Export with Missing Data

sql,postgresql,shell,hadoop,sqoop

I solved the problem by changing my reduce function so that if there were not the correct amount of fields to output a certain value and then I was able to use the --input-null-non-string with that value and it worked.

Multiple line search in a file using java or unix command

java,shell,unix,command

You can find like this. File file = new File("data/pattern.txt"); Pattern pat = Pattern.compile("subclass \"Pool1\" 11:22:33:44:55:66 \\{\\s*dynamic;\\s*\\}"); String content = Files.lines(file.toPath()).collect(Collectors.joining("\n")); Matcher m = pat.matcher(content); while (m.find()) { System.out.printf("found at %d-%d%n", m.start(), m.end()); } ...

Need to update a text file with new content found in an other text file

bash,shell,text-files

You could use output redirection cat newtodo.txt > todo.txt <br> or You could rename newtodo.txt mv newtodo.txt todo.txt ...

Using the shell provided with NodeJS

javascript,node.js,shell,require,node-modules

As per issue #5431, looks like the Node.JS REPL doesn't find globally-installed modules and this is expected behaviour. In the article linked from that issue, it reads: If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your...

Check for decimal point and add it at the end if its not there using awk/perl

regex,perl,shell,awk

In awk Just sub for those fields awk -F, -vOFS="," '{sub(/^[^\.]+$/,"&.",$6);sub(/^[^\.]+$/,"&.",$11)}1' file or sed sed 's/^\(\([^,]*,\)\{5\}[^.,]\+\),/\1./;s/^\(\([^,]*,\)\{10\}[^.,]\+\),/\1./' file ...

gimp: resize and “unsharp mask” via script

shell,scale,gimp

As you are on Ubuntu, you likely already have ImageMagick installed - convert, identify and mogrify commands, amongst others. So, make a copy of your data and try something like this on a copy: mogrify -resize 640x480 -unsharp 6x3+1+0 *.jpg or maybe this mogrify -resize 1024x768 -sharpen 0x1.0 *.tif to...

Running executable files using Haskell

shell,haskell,command-line-arguments,executable

The documentation for readProcess says: readProcess :: FilePath Filename of the executable (see RawCommand for details) -> [String] any arguments -> String standard input -> IO String stdout When it's asking for standard input it's not asking for a file to read the input from, but the actual contents of...

how to install shelled in eclipse luna

bash,shell,eclipse-plugin

Finally I managed to install it by deleting eclipse luna and downloading it again from scratch... I still don't understand why I got the errors in my old eclipse... It is rather annoying since I had a lot of plugins installed in my old eclipse and I had to re-install...

Delete some lines from text using Linux command

linux,shell,sed,grep,pattern-matching

The -v option to grep inverts the search, reporting only the lines that don't match the pattern. Since you know how to use grep to find the lines to be deleted, using grep -v and the same pattern will give you all the lines to be kept. You can write...

mv Bash Shell Command (on Mac) overwriting files even with a -i?

osx,bash,shell

Apparently the manual entry clearly states: The -n and -v options are non-standard and their use in scripts is not recommended. In other words, you should mimic the -n option yourself. To do that, just check if the file exists and act accordingly. In a shell script where the file...

count the values based on condition in log

linux,shell

try this: cat path_to_your_log_file|awk '{split($2,res,":");var=res[1]":"res[2]":"res[3];counter[var]+=$1}END{for(i in counter){print counter[i],i}}' ...

Matching string inside file and returning result

regex,string,bash,shell,grep

Using sqlite3 from bash on OS X seems fairly straightforward (I'm no expert at this, by the way). You will need to find out which table you need. You can do this with an interactive session. I'll show you with the database you suggested: /Users/fredbloggs> sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db SQLite version...

Is it possible to run command “route -n” specifically for a NIC

linux,shell,scripting

Do you want see route for ether0, you can use below command ip -o route show dev ether0 or ip route show | grep ether0 or route -n | grep ether0 or netstat -nr | grep ether0 To see NIC for ether0, you can use ifconfig command and Gateway NIC...

Use Unix Executable File to Run Shell Script and MPKG File

osx,shell,unix

The most common issue when handling variables containing paths of directories and files is the presence of special characters such as spaces. To handle those correctly, you should always quote the variables, using double quotes. Better code would therefor be: sudo sh "$path/join.sh" sudo sh "$path/join2.sh" It is also advised...

Storing data in shell

shell,sh

This script will get called and passed a customer number. myEmailFinder "$CustID" I want to populate a variable based on the passed in customer number. emailAddr=$( myEmailFinder "$CustID") I want to pull an e-mail associated with that customer number and populate a variable with it. I would prefer this...

“exec not found” when using variable in exec

linux,shell

It is caused by shell not performing variable expansion on the left side of the redirection operator. You can use a workaround: eval exec "${PIPE_ID}"'<>"spch2008"' It will force the shell to do variable expansion, producing eval exec 100'<>"spch2008"' Then the eval built-in will feed the command to the shell, which...

Linux-wget command

linux,shell,wget

Try this to create a string variable n, with no leading whitespace (thanks @011c): n="10.0.0.135.527" wget http://infamvn:8081/nexus/content/groups/LDM_REPO_LIN64/com/infa/com.infa.products.ldm.ingestion.server.scala/"$n"-SNAPSHOT/com.infa.products.ldm.ingestion.server.scala-"$n"-20150622.210643-1-sources.jar ...

Mac OSX - Allow for user input in shell script via GUI or Prompt

osx,bash,shell

From what I understand I would recommend you look in to Applescript as this will allow you to have a GUI Interface as well as executing 'SHELL' commands. First of all I would open 'Script Editor' program that comes preinstalled on Mac's This is an example script which asks for...

cat /dev/null to multiple files to clear existing files like logs

linux,bash,shell,command-line,tee

Hard coded solutions tee Echo nothing and simple send it to multiple files using the tee command. Like this: $ echo -n | tee file1 file2 file3 file4 file5 All files in that list will be empty and created if they don't exist. Applied to your answer this would be:...

how to check a directory exist and can write file

oracle,shell,unix,sql-loader

For Checking Diretory is present if [ -d "$YOUR_DIRECTORY" ] then #Operation when directory is present else #Operation when directory is not present fi For checking if directory is writeable if [ -w "$YOUR_DIRECTORY"] then #Operation when directory is writeable else #Operation when directory is not writeable fi Regarding Oracle...

shell command to skip file in sequence

shell,sh

in the loop, test if file exists before calling a program operating on that file: for i in $(seq 0 100); do INPUT=c2.$(($i*40+495)).bin test -e $INPUT && ./f.out $INPUT c2.avg.$(($i*40+495)).txt done This way the ./f.out ... will be executed only for existing input files. See man test for details. BTW,...

How do I align my output?

shell

I'd rewrite that as: #!/bin/bash while read -ra hello; do name=${hello[8]} if [[ $name == "$1"* ]]; then log=${hello[2]} echo "$log $name" fi done | column -t read -ra splits the input line and stores the words in the "hello" array. [[ $name == "$1"* ]] is a built-in way...

How to run shell-commands in IPython? (Python Profiling GUI tools)

python,shell,profiling,ipython,ipython-magic

From the ipython example in the pyprof2calltree documentation: >>> from pyprof2calltree import convert, visualize >>> visualize('prof.out') >>> convert('prof.out', 'prof.calltree') Or: >>> results = %prun -r x = taylor_sin(500) >>> visualize(results) >>> convert(results, 'prof.calltree') You could also try: >>> %run -m pyprof2calltree -i prof.out -o prof.calltree ...

oh-my-zsh error after upgrade: ~/.oh-my-zsh/lib/misc.zsh:3: parse error near `then'

shell,zsh,zshrc,oh-my-zsh

Use upgrade_oh_my_zsh upgrade to the latest version. This issue fix here...

shell script to shutdown/restart Linux system

linux,shell

Yes, use the -S switch which reads the password from STDIN: $echo <password> | sudo -S <command> Exposing your password is generally bad idea search for something that can protect / hide it. In the past I've used Jenkins plugins to do this while executing the scripts regularly....

Doubts with for loop in Unix

bash,shell,unix,for-loop

A for loop in shell scripting takes each whitespace separated string from the input and assigns it to the variable given, and runs the code once for each value. In your case b* is the input and $var is the assigned variable. The shell will also perform expansion on the...

mysql query to select two columns from same table

mysql,shell

You can use the following query to produce the required result set: SELECT KID, MAX(CASE WHEN REDO = 1 THEN REV) AS REDO1, MAX(CASE WHEN REDO = 2 THEN REV) AS REDO2 FROM Table1 GROUP BY KID The above uses conditional aggregation in order to place all REV values that...

shell script to read each line and run the condition

shell

Are you saying that you want to detect when 5 consecutive rows contain a value greater than 200? If so: awk '{a = $1 > lim ? a + 1 : 0} a > seq {print "alert on line " NR}' lim=200 seq=5 input It's not clear what you actually...

mongodb shell is written in JavaScript. Why UNIX binary then?

javascript,mongodb,shell

The mongo shell, as well as the mongod database process are implemented in C++. You can get the source code and build it yourself here: https://github.com/mongodb/mongo

AWK count number of times a term appear with respect to other columns

linux,shell,command-line,awk,sed

Almost same as the other answer, but printing 0 instead of blank. AMD$ awk -F, 'NR>1{a[$2]+=$3;b[$2]++} END{for(i in a)print i, a[i], b[i]}' File pear 1 1 apple 2 3 orange 0 1 peach 0 1 Taking , as field seperator. For all lines except the first, update array a. i.e...

Shell script to check if mysql is up or down

mysql,shell,cron

You can use below script #!/bin/bash USER=root PASS=root123 mysqladmin -h remote_server_ip -u$USER -p$PASS processlist ###user should have mysql permission on remote server. Ideally you should use different user than root. if [ $? -eq 0 ] then echo "do nothing" else ssh remote_server_ip ###remote server linux root server password should...