FAQ Database Discussion Community


Redirection based on variables assigned within while loop setup

shell,while-loop,do-while
I want to access while loop variable out side the loop while read line do ... ... ... done < $file > /home/Logs/Sample_$line_$(date +"%Y%m%d_%H%M%S").log In the above example whatever the log file is getting generated that doesn't have the value for the line variable. i.e. $line is not working here....

Deleting upto a line

bash,perl,shell,sed,scripting
I have a line that looks like: foo cat dog = -48.34277635 foo(horse->0) = -60.34277635 and I only want the last set of numbers: -60.34277635 The line is formatted with that exact spacing. I've looked everywhere for a simpler solution, but I can't find anything without chopping the file piece...

shell command to skip file in sequence

shell,sh
I run a C++ code for several data files in sequence using: for i in $(seq 0 100); do ./f.out c2.$(($i*40+495)).bin `c2.avg.$(($i*40+495)).txt; done` Now if some input files are missing, say c2.575.bin is missing then the command is not executed for the rest of the files. How could I modify...

Identifying when a file is changed- Bash

bash,shell,unix
So in my bash shell script, I have it running through a for loop. Inside the for loop, I use find "$myarray[i]" >> $tmp to look for a certain directory each time through the loop. Sometimes, it finds the variable in myarray[i] and sometimes it doesn't. When it does find...

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

node.js,shell,params
I would like to execute an shell program who require any params with Node.js How can I do that ?...

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

linux,bash,shell,unix,ksh
This question already has an answer here: Bash expand variable in a variable 4 answers I hava a column in database which contains the following data: sql_proc|test_sql.sql|/home/Desktop/myfile.txt|$IMP_FILES/myFolder|convert I have fetched this into a variable and I have used the cut command with "|" as delimiter and saved each field...

Reading from linux command line with Python

python,linux,shell,command-line
Is there a way to read data that is coming into the command-line, straight into another Python script for execution?

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

regex,perl,shell,awk
I have test.dat file with values given below: 20150202,abc,,,,3625.300000,,,,,-5,,,,,,,,,,,,,,,,,,,,,, 20150202,def,,,,32.585,,,,,0,,,,,,,,,,,,,,,,,,,,,, 20150202,xyz,,,,12,,,,,0.004167,,,,,,,,,,,,,,,,,,,,,, My expected output is shown below: 20150202,abc,,,,3625.300000,,,,,-5.,,,,,,,,,,,,,,,,,,,,,, ^. added here 20150202,def,,,,32.585,,,,,0.,,,,,,,,,,,,,,,,,,,,,, ^. added here 20150202,xyz,,,,12.,,,,,0.004167,,,,,,,,,,,,,,,,,,,,,, ^. added here So if column 6 and 11 doesn't have decimal point in it, then we should add '.' at the end of...

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

python,shell,profiling,ipython,ipython-magic
I am trying to do file profiling in IPython, generate some profiling stats output and then pass it to some Python profiling GUI tools like KCachegrind. Here is my code trying to do that. All codes are executed in IPython. # example function for profiling def factorial(n): if n ==...

Doubts with for loop in Unix

bash,shell,unix,for-loop
Sorry if its sounds dumb but I'm currently studying for an exam to apply for a job (administrative one) and I learnt about java, php, python but not much about unix scripts. I can see it's very similar to php in structure and I have many questions about it ....

how to spy on linux binaries for testing of shell scripts

linux,bash,shell,testing,spy
sorry if this is a duplicate, i had no idea what to search for... my use case is more complex, but can be narrowed down to the following problem: i want to run a bash script, which invokes all sorts of binaries, for example: grep. i want to assert that...

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

regex,linux,shell,unix,replace
I have an extremely big (many GBs in size) file that looks like [x data1 data2 data3 data4 y] [a data5 data 6 data7 data 8 b> [x data y] ...and so on How to replace newlines (which might be surrounded by spaces) with a single space, but only if...

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

bash,shell
Example: #!/bin/bash command_a # starting a executable command_b # should be executed after after exiting A A is exited via ctrl+C. I didn't really know how to search for this....

ShellExecute doesnt work if some parameters are just int type

c#,windows,shell,interop
I have the below code which is to launch any .exe (in this example its notepad.exe). But this code is not working. though there are no compilation issues. [DllImport("shell32.dll", CharSet = CharSet.Auto)] static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo); public static void exev() { SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); info.cbSize =...

Passing GET variables to shell_exec in PHP

php,shell,get,mamp
I'm trying to run a shell script in PHP on my server that use youtube-dl to download a video. My code look like this: <form action="download.php" method="get"> <input type="text" name="link"><br> <input type="submit"> </form> and my download.php look like this: <?php $link = escapeshellarg($GET["link"]); $output = shell_exec('/Applications/MAMP/cgi-bin/youtube-dl ' .$link. ' 2>&1');...

Passing commands to subprocess in shell

bash,shell,vagrant,karaf
if a certain command (in my case ./karaf) runs a sub-process in a shell, that accepts its own commands, is there someway to execute the subsequently listed commands in a script as commands to the subprocess? For example, sudo ./karaf opens a process in the shell that accepts its own...

how to check a directory exist and can write file

oracle,shell,unix,sql-loader
I need to check directory test_file exist, if yes then need to check directory test_file is having write permission so that files will be writen in the same. this functionality i needed in shell script(ksh). What would be return code from sqlldr for single table load and multi table...

How to test if a command is a shell reserved word?

bash,shell
I am writing a bash script and I would like to verify if a string is a shell reserved word (like if, for, alias, etc...). How can I can do this?...

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

linux,bash,shell,awk,sed
I have a CSV file with columns A,B,C,D. Column D contains values on a scale of 0 to 1. I want to use AWK to write to a new column E base in values in column D. For example: if value in column D <0.7, value in column E =...

mysql query to select two columns from same table

mysql,shell
Below are the sample tables I'm working on Table 1 ╔════╦══════════════╦══════╗ ║ KID║ REV ║ REDO ║ ╠════╬══════════════╬══════╣ ║ 1 ║ 43453453345 ║ 2 ║ ║ 1 ║ 2433423423 ║ 1 ║ ║ 2 ║ 23423423 ║ 1 ║ ║ 2 ║ 5566533 ║ 2 ║ ╚════╩══════════════╩══════╝ I need to...

gimp: resize and “unsharp mask” via script

shell,scale,gimp
I need to do the same operations for more than 60 files: scale image unsharpen mask Is it possible to execute this from a script possibly passing the scale value ? I'm on Ubuntu if this could influence the answer. edit: What I need to do is to resize some...

Storing data in shell

shell,sh
I have a need to store a list of e-mails in a shell script. This script will get called and passed a customer number. depending on the customer number I want to populate a variable based on the passed in customer number. I am not sure how to accomplish this...

Use Xargs to wait for enter key

linux,bash,shell,xargs
So, I have a list of files that I want to use to generate a new set of groups of files. I want to open up these groups (multiple files) together at once. Edit them. Then go back to the terminal, hit enter, and open up the next group of...

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

osx,bash,shell
first time post so please let me know how I could improve.. I created a shell script which requires a person to input their name and then generates a report. The script works as needed when chmod'd into an executable script and run from terminal. But, I would like to...

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

linux,bash,shell,command-line,tee
A good way to clear logs(syslog has a handle on file) which have frozen my linux server(out of space) I tried cat /dev/null > fileABC; cat /dev/null/ > fileXYZ How can I clear multiple files by cat /dev/null to multiple files in an efficient or single command. ...

Shell script with jar file at the end

java,shell,jar
I download an archive file. In the archive there will be a file that has a .sh. extension. When I opened that file with VI I found the below code in the beginning of the file: #!/bin/sh MYSELF=`which "$0" 2>/dev/null` [ $? -gt 0 -a -f "$0" ] && MYSELF="./$0"...

Running executable files using Haskell

shell,haskell,command-line-arguments,executable
Say there's a C++ code that I've compiled into an executable using: g++ test.cpp -o testcpp I can run this using Terminal (I'm using OS X), and provide an input file for processing inside the C++ program, like: ./testcpp < input.txt I was wondering if doing this is possible, from...

Shell script to check if mysql is up or down

mysql,shell,cron
I want a bash shell script that i can run using a cron job to check if mysql on a remote server is running. If it is, then do nothing, other start the server. The cronjob will be checking the remote server for a live (or not) mysql every minute....

adb shell command from batch file

android,shell,adb
I have a .bat file that runs script for testing an app and printing the log to file i have all the commands i tested them manually. Problem: after entering the command adb shell, the shell opens in the command prompt. I wrote the next commands that are entered in...

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

linux,shell,command-line,awk,sed
Given a CSV file: id, fruit, binary 1, apple, 1 2, orange, 0 3, pear, 1 4, apple, 0 5, peach, 0 6, apple, 1 How can i calculate for each unique values in fruit, the number of times the binary value =1 / number of occurences of that fruit...

File Handling and making directories to match in bash

bash,shell,sorting,matching,file-handling
I have these files: File_1.2.txt, File_1.5.txt, File_2.3.txt, and File_4.7.txt. I want to make directories for them and sort them into the directories, like below. Dir_001 -> File_1.2.txt File_1.5.txt Dir_002 -> File_1.2.txt File_2.3.txt Dir_003 -> File_2.3.txt Dir_004 -> File_4.7.txt Dir_005 -> File_1.5.txt Dir_007 -> File_4.7.txt So a directory is made for...

How to store command line arguments for future use?

bash,shell
I have a big bash script (version 3.2.51(1)-release) and I need to store command line arguments for use in the script. I checked many threads here and people suggested to use "$@" to access all arguments. If I run this script (test.sh) - #!/bin/bash echo "$@"; $> ./test.sh 1 2...

Calling find more than once on the same folder tree

linux,bash,shell,unix,find
I'm running a find command multiple times on the same group of files. The results of my find commands are usually disjoint sets, AKA I'm running find -mmin +35; find -mmin -25, and doing different things to the results. It seems sort of silly to search through the entire file...

Is [ $var ] an acceptable way to check for variables set/empty in bash?

bash,shell,variables
I wrote some bash before reading this popular question. I noticed the way I was doing things doesn't show up in any of the answers so I was curious if there is a danger/bug to my logic that I am not seeing. if [ ! $1 ] || [ $2...

Use Function From Earlier in Function Path

linux,shell,fish,aliases
In fish, is it possible to reference or use a function inside another function of the same name? For example, fish has a function ls at /usr/local/share/functions/ls.fish, which sets some default parameters based on things like OS and whether the shell has colors. I want to define another function that...

count the values based on condition in log

linux,shell
I have a log like below 11 13/06/2015:00:02:37 10 13/06/2015:00:02:38 7 13/06/2015:00:02:39 10 13/06/2015:00:02:40 1 13/06/2015:00:02:42 1 13/06/2015:00:02:50 1 13/06/2015:00:02:54 2 13/06/2015:23:41:46 1 13/06/2015:23:41:47 2 13/06/2015:23:41:48 1 13/06/2015:23:41:49 2 13/06/2015:23:41:50 1 13/06/2015:23:41:51 2 13/06/2015:23:41:52 1 13/06/2015:23:41:53 2 13/06/2015:23:41:54 1 13/06/2015:23:41:55 1 13/06/2015:23:59:50 2 13/06/2015:23:59:51 2 13/06/2015:23:59:52 2 13/06/2015:23:59:53 2 13/06/2015:23:59:54...

How to check whether string matches that of a domain

regex,bash,shell
I have written code to test whether a string matches a domain like this: host=$1 if [[ $host =~ ^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}$ ]] ; then echo "it is a domain!" fi With help from this website but for some reason, the above is not working. Do you have any idea why?...

Run a command with sudo in bash shell

shell,cron,sudo
How can i run a command in shell script with sudo? This script will be run by a cron job, so there should be no human intervention to enter a password manually.

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

linux,bash,shell
Suppose the user of parent shell is foo. If you run something like sudo -u bar -i, then you are in a child shell with user bar. So, how can I find out the user of the parent shell inside the child shell? Namely, in the case above, how can...

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

shell,command-line,awk,terminal
I'm a complete newbie to using command-line utilities and am wondering how to process information as following: mapping.txt: 80 001 002 81 011 012 013 014 82 021 022 ... input.txt: 81 103823044 80 103823054 81 103823064 ... Desired output.txt: 103823044|011| 103823044|012| 103823044|013| 103823044|014| 103823054|001| 103823054|002| 103823064|011| 103823064|012| 103823064|013| 103823064|014|...

Why does `su` not work in Jenkins?

shell,jenkins,su
su doesn't seem to work as intended when run in Jenkins build job script. su username1234 whoami returns jenkins My initial guess is that each line of the Jenkins shell script is a new shell. But doing repeated echo $$ on separate lines shows that's not the case. ...

shell script to read each line and run the condition

shell
I have a log file which has the below data 120 140 200 110 200 200 120 90 100 I want to read this file and compare each line(number) with 200, and if it crosses 200 - then it has to compare the next word till the 5 consecutive which...

Delete some lines from text using Linux command

linux,shell,sed,grep,pattern-matching
I know how to match text using regex patterns but not how to manipulate them. I have used grep to match and extract lines from a text file, but I want to remove those lines from the text. How can I achieve this without having to write a python or...

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

bash,shell,jenkins
I have a Jenkins project with one "Execute shell" that executes some bash commands and exports one variable to the env. variables: #!/bin/bash ... TARGET_FULLPATH="blablabla" export TARGET_FULLPATH In addition, I have configured to "Post-build Actions" with: "Trigger parameterized build on other projects" "Current build parameters" "Predefined parameters" -> FULLPATH=$TARGET_FULLPATH But,...

Random password generate in shell script with one special character

bash,shell,unix,random,passwords
I have following code </dev/urandom tr -dc 'A-Za-z0-9@#$%&_+=' | head -c 16 which is randomly generating password perfectly. I want two changes: It should only contain 1 special symbols that i have listed there It should choose random length of the password I tried with length = $(($RANDOM%8+9)) then putting...

What is the difference between `./example.sh` and `sh example.sh`

linux,bash,shell
I am trying to play with bash and arrays. But executing a sample script, I got an unexpected syntax error message: example.sh: 3: example.sh: Syntax error: "(" unexpected. And this is the script #!/bin/bash array=( one two three ) If I run the script with ./example.sh it works and no...

Unexpected concatenation of shell variables

shell
When I try executing the following lines of code on shell- #!/bin/sh mc=XX:XX:XX:XX; dd bs=1 count=2 if=/dev/random 2>/dev/null |hexdump -v -e '/1 ":%02X"' echo $mc the output I get is :04:CCXX:XX:XX:XX ,i.e. the X's are concatenated at the end instead of the beginning. I also tried this (as mentioned in...

docker run local script without host volumes

database,shell,docker,docker-compose
The goal is to add data to my database server containers of a multi-container web app from a download using curl once the database containers are running. I can do this from docker-compose.yml or from docker run independent of the web app, as long as I use host volumes. How...

“exec not found” when using variable in exec

linux,shell
I met a strange problem. mkfifo "spch2008" exec 100<>"spch2008" It's OK. But, when i use variable to replace "100", error occurs. exec: 100: not found PIPE_ID=100 mkfifo "spch2008" exec ${PIPE_ID}<>"spch2008" I don't know the reason. please hlep me,thanks....

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
I have a very huge file which looks like this: <a>text</a>text blah <b>data1</b>abc<b>data2</b> <b>data3</b>blahblah <c>text</c> <d>text</d> <x>blahblah<b>data4 data5 data6</b> <b>data7 </x> That is, its formatting is unpredictable. I need to extract each <b>...</b> item (it might contain multiline text!) and put every one of them in a single separate line....

Multiple line search in a file using java or unix command

java,shell,unix,command
I want to find the following pattern in a file like subclass "Pool1" 11:22:33:44:55:66 { dynamic; } the above pattern I have to find in a file. How can I find either using java or Unix command?...

Why is Unix/Terminal faster than R?

r,bash,shell,unix,terminal
I'm new to Unix, however, I have recently realized that very simple Unix commands can do very simple things to large data set very very quickly. My question is why are these Unix commands so fast relative to R? Let's begin by assuming that the data is big, but not...

Using AWK to parse fields with commas

regex,bash,shell,awk
Edited - TLDR: Using awk to parse fields that include commas. # original config file - confile1 $ cat confile1 list=( app1,"HOSTNAME - port - application name - alert1",99.0,99.0 app2,"HOSTNAME - port - application name - alert1",99.0,99.0 app3,"HOSTNAME - port - service name - alert2",99.0,99.0 web1,"URL - HOSTNAMES(01,02) - http://someurl.com/...

launch several scripts located in subdirectories

linux,bash,shell
Here is my problem. I have a directory that contains multiple sub-directories. In each sub-directory, there is at least one script sh. I want to do a script that execute sequentially all this scripts. I am pretty new to linux. Thanks for your help, ...

Piping echo into sendmail in rc.local fails

linux,shell,email,sendmail,boot
I'm trying to get my system to send me an email when the system boots. Using the following command works as intended: echo -e "TO:my-email-address@gmail.com \nSUBJECT:System Booted \n\nBeware I live! \n"$1 | sendmail -t -vs But if I add it to rc.local like so: #!/bin/sh -e # # rc.local #...

Nested For loop in makefile

shell,makefile,make
I am trying to loop through the .c files in a specific directory through the makefile. i used the following code, but it seems not working: DIR= Sources \ Sources_2 @for entry in ${DIR} ; \ do \ @for i in $${entry}/*.c ; \ do \ echo "Processing $${i}"; \...

shell script cut from variables

bash,shell,shellcode
The file is like this aaa&123 bbb&234 ccc&345 aaa&456 aaa$567 bbb&678 I want to output:(contain "aaa" and text after &) 123 456 I want to do in in shell script, Follow code be consider #!/bin/bash raw=$(grep 'aaa' 1.txt) var=$(cut -f2 -d"&" "$raw") echo $var It give me a error like...

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

javascript,mongodb,shell
Is that true, that MongoDB shell is written in JavaScript? If yes why it's a UNIX binary? Not a webapp for browser? > less /usr/local/bin/mongo "/usr/local/bin/mongo" may be a binary file. See it anyway? > file /usr/local/bin/mongo /usr/local/bin/mongo: Mach-O 64-bit executable x86_64 ...

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

linux,string,bash,shell,variables
I would like to extract the first letter of dashed separated words value of my bash variable, like this: MY_TEXT=this-is-my-custom-text I would like to create a second variable like this: MY_INITIALS=timct...

Expand passed arguments before printing with puts to virtual server

shell,tcl,expect
I am having trouble with an expect script not evaluating arguments. Everything in the puts ${file_id} block (simplified obviously) gets placed onto a virtual machine and is later used to for configuration. The block you see puts the same code into a local directory for me to see if things...

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

shell,zsh,zshrc,oh-my-zsh
today I upgrade my oh-my-zsh and then start this error: ~/.oh-my-zsh/lib/misc.zsh:3: parse error near `then' Inside this file there is this shell loop... ## Load smart urls if available for d in $fpath; do if [[ -e "$url/d-quote-magic"]]; then autoload -U url-quote-magic zle -N self-insert url-quote-magic fi done I think...

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

python,bash,shell
I have a shell script that needs to run a python script. The python script may be passed an argument. python pgm32.py $args But when the argument passed has an escape sequence or if I encase it in quotes, the python scripts does not recognize it. For instance say args...

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

linux,bash,shell
For example say I have: filename1.ext1 filename1.ext2 filename2.ext1 filename2.ext2 I need to write a shell script to feed these files into a program like so: program filename1.ext1 filename1.ext2 program filename2.ext1 filename2.ext2 Additionally the .ext1 files must be entered first and the .ext2 files second. Any help would be appreciated....

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

bash,shell
I want to do the following and see the commands that are issued and the result. cd /WORKING_DIRECTORY make clean make mrproper make VARIANT_DEFCONFIG=msm8974_sec_hlte_spr_defconfig msm8974_sec_defconfig SELINUX_DEFCONFIG=selinux_defconfig make ...

how to install shelled in eclipse luna

bash,shell,eclipse-plugin
I am trying to install shelled in latest eclipse luna and getting the next error: An error occurred while collecting items to be installed session context was:(profile=epp.package.cpp, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=). No repository found containing: osgi.bundle,org.eclipse.egit,3.7.1.201504261725-r No repository found containing: osgi.bundle,org.eclipse.egit.core,3.7.1.201504261725-r No repository found containing: osgi.bundle,org.eclipse.egit.doc,3.7.1.201504261725-r No repository found...

Diffing two variables in a shell script

bash,shell
I have a shell script that has the following line diff <(echo "$var_1") <(echo "$var_2") both variables could contain new lines so there, at least from my own understanding, must be "" around the echo statements. However no matter if I escape the "s or not bash continues to say...

Tmux breaks zsh aliases

bash,shell,alias,zsh
I have a file .aliases that I point to in my .zshrc file DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" if [ -f $DIR"/.aliases" ]; then . $DIR"/.aliases" fi This code is the same in my .bashrc file (in the process of switching over to zsh). The aliases...

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

python,shell
I'm using Python to call cscope internally. For this I'm using subprocess.call. The problem is that it's not working without shell=True The following code works as expected: import subprocess subprocess.call("cscope -d -L0'temp'", shell=True) But the following doesn't, it returns with 0 status code, but there is no output import subprocess...

Redirect output from file to stdout

bash,shell,unix,stdout
I have a program that can output its results only to files, with -o option. This time I need to output it to console, i.e. stdout. Here is my first try: myprog -o /dev/stdout input_file But it says: /dev/ not writable I've found this question that's similar to mine, but...

Missing one condition to display a string

shell
I am working on a small script that simply takes a parameter and read the output of ls -l and displays the user and name of the file that start with that parameter. For exemple : $> ls -l | ./script.sh "ok" John ok_file Mark ok_test Here is what the...

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

python,windows,shell,command,virtualenv
On windows vista, I need a script that starts the activate (to activate the virtualenv) script in C:\Users\Admin\Desktop\venv\Scripts\ And later, in the virtual environment, starts to the manage.py runserver in the folder : C:\Users\Admin\Desktop\helloworld\ how should I do? What modules should I use?...

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

bash,shell,text-files
my text file looks like this 1 get a 06-05-2000 2 get b 06-05-2001 3 get c 06-05-2002 4 get d 06-05-1442 5 get e 06-05-1998 6 get f 06-05-1909 I want to read what is after the first \t (tab) and store that in varA and what is after...

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

linux,r,bash,shell,csv
I'm using Rio and I have a sample.csv which looks as following hour,count 0300,0 0300,0 0300,1 0300,1 0300,2 0301,1 0301,2 0301,2 0301,3 I run following command: $ < sample.csv Rio -ge 'g + geom_bar(df, aes(hour, count))' | display and I get display.im6: no decode delegate for this image format `/tmp/magick-Gvr3kRZh'...

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

shell,awk,sed,grep,sh
This question already has an answer here: Remove duplicates from text file based on second text file 4 answers I have a data.txt file with a lot of lines in it and a lines.txt that contains some lines. I want to delete all lines from data.txt that match any...

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

linux,bash,shell,unix,awk
I would like to extract sum, mean and average in each 6 numbers interval from a column. I found many discussions related to this problem, but all those are for whole column. e.g. To compute sum of a column: awk '{sum+=$1} END { print sum}' To calculate Average: awk '{sum+=$1}...

shell script to shutdown/restart Linux system

linux,shell
Is there any suitable shell script for shutting down or restarting a Linux machine? I have tried a shell script for shutdown, but when I enter sudo shutdown it will ask for the password. How we can enter the password using the script?

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

shell,text-files
I want to check if .todo.txt is empty or not. If is is empty, I want to add the echo in the file, and if it already has content, I want to do something else. I tried: hasData() { echo "Hello" } isEmpty() { echo -e "$n\t$comment\t$dueD/$dueM/$dueY " >> .todo.txt...

remove line from file if more than one pattern appears in different line

shell,awk,sed,file-processing
I have a file with a patter like this: 1 1 1 2 0 1 0.5 1 2 2 2 0 2 0.5 2 1 1 1 0 1 0.25 2 1 2 2 0 2 0.5 2 3 3 3 0 3 0.25 I want to remove a line...

Linux-wget command

linux,shell,wget
I need a quick help on customizing my wget command in a shell script: The wget command looks something like this: wget http://infamvn:8081/nexus/content/groups/LDM_REPO_LIN64/com/infa/com.infa. products.ldm.ingestion.server.scala/10.0.0.135.527-SNAPSHOT/com.infa.products.ldm.ingestion.server.scala-10.0.0.135.527-20150622.210643-1-sources.jar Here I'd like to add the 10.0.0.135.527 in a variable, so I created a script something like this: n = 10.0.0.135.527 wget...

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

php,mysql,database,shell,command-line-interface
I'm having trouble with a database export that is too big for phpmyadmin to handle. I'm curious what the syntax would be for exporting a mysql database from a remote server and getting the export file into a specific folder on my own computer, all using the command line. Say...

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

linux,shell,scripting
I am fairly new to linux I wanted to ask if its possible in linux commands to run a "route -n" command to retrieve information for a specific NIC. E.G route -n ether0. Because currently it shows me for all the NIC's but what if I want just for one?...

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

osx,bash,shell
I am flattening a directory of nested folders/picture files down to a single folder. I want to move all of the nested files up to the root level. There are 3,381 files (no directories included in the count). I calculate this number using these two commands and subtracting the directory...

Showing progress as shell script runs

shell,sh,snmp,net-snmp
I would like to display something showing that the script is still gathering information from a device. Whether it be hash marks or periods. As you can see below when it starts its walk of a device it echos its start time. It is here I would like to show...

Error while executing lsof from bash script

linux,bash,shell,scripting
I am trying to check for the process which are running on a particular port and if present kill them, as i have to start another process on that port. Below is my code snippet. #!/usr/bin/env bash TEST_CASE_PATH="$HOME/Projects"; #kill Previous Process Running on port 9130 OUTPUT="$(ls -1)" echo "${OUTPUT}" #...

Bash - How to discriminate control operator from metacharacter?

bash,shell
According to bash manual: control operator A token that performs a control function. It is a newline or one of the following: ‘||’, ‘&&’, ‘&’, ‘;’, ‘;;’, ‘|’, ‘|&’, ‘(’, or ‘)’. metacharacter A character that, when unquoted, separates words. A metacharacter is a blank or one of the following...

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

bash,shell,curl,command-line,pipe
When I run the curl command and direct the data to a file, I get back the content of the site as expected. $ curl "www.site.com" > file.txt $ head file.txt Top of site ... However, this command shows a progress bar, which I do not want: % Total %...

Matching string inside file and returning result

regex,string,bash,shell,grep
I've got a few peculiar issues with trying to search for a string inside of a .db file. The way I tried was by using grep, which does apparently find the string(s), although this is the output: $ grep "ext" *.db Binary file enormous.db matches There are a couple problems...

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

regex,bash,shell,ssh,sed
I am trying to replace the bottom one of these 2 lines with sed in a file. <rule>out_prefix=orderid ^1\\d\+ updatemtnotif/</rule>\n\ <rule>out_prefix=orderid ^2\\d\+ updatemtnotif/</rule>\n\ And the following command seems to do that when executed as a command at the bash prompt sed -i 's@out_prefix=orderid ^2\\\\d\\+ updatemtnotif/@out_prefix=orderid ^2\\\\d\\+ updatemtnotif_fr/@g' /opt/temp/rules.txt however, when...

Group of data in shell language

linux,bash,shell
I wonder if the data in the group aren’t numbers ; the script works? When x="1 2 3" I can do a for loop: for i in $x I wonder if this is correct : read x read y xm=`cat $x` ym=`cat $y` zm="$xm $ym" for i in $zm do...

find numbers divisible by 3 in csv file using shell script

bash,shell,unix,awk
I have csv file having content like below : 1|2|3 4|5|6 7|8|9 Now I would like to find the numbers which are divisible by 3 using shell scripting. I would like to use awk command for this. I am learning shell scripting. So could you please help me out to...

Vagrant shell provisioning phpPgAdmin password

bash,shell,vagrant,vagrantfile,phppgadmin
How would I get my Vagrant shell script to supply the password when creating a user while provisioning phpPgAdmin? ie. when I supply this command sudo htpasswd -c /etc/phppgadmin/.htpasswd vagrant it prompts for a password for the vagrant user so I can login to phpPgAdmin. How can I script this...

Use Unix Executable File to Run Shell Script and MPKG File

osx,shell,unix
I have 2 shell scripts and 2 mpkg installer, I am trying to use an unix excitable file to run them all. here is the script I have, but it always has error message "No such file or directory" ? #!/bin/sh # Find the absolute script current path path=$( cd...

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

bash,shell,text-files
hello i was update a file, removing some content from it, now that i have to new file i want it's content back to the original file hidden=Desktop/newtodo.txt do echo -e "$y \t $line" >> $hidden y=$(($y+1)) done newtodo.txt > todo.txt i have content in todo.txt i updated them in...

Using the shell provided with NodeJS

javascript,node.js,shell,require,node-modules
Once you've installed NodeJS, you'll have a executable in your computer named NodeJS which is a shell. I was wondering what can I do with that... here you're able to run JS code as, for example, in the browser's console, great. Now, is it possible to require modules in that...

Fail Jenkins job when nosetests fail

python,shell,jenkins,continuous-integration
I am managing deployment / CI of a Flask app through Jenkins. I have a build step in the form of an executed shell which runs a shell script in the host that in turns runs nosetests. The Jenkins shell command looks like so: $WORKSPACE/ops/test_integration.sh integration.sh looks like so: SETTINGS_FILE="settings/integration.py"...

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

git,bash,shell,unix,binary
I am on a Macbook Pro on Mac OS X 10.10 (Yosemite). When I go to /usr/bin, git is there as a unix executable file. When I open it up in Sublime Text, all I get is unreadable machine code. However, when I open up a different Unix executable file—in...

How do I align my output?

shell
I'm writing a script that takes a parameter and reads the output of ls -l. It then displays the user and the name of the file STARTING with that parameter. For example : $> ls -l | ./script.sh "o" John ok_test RandomUser o_file My script works just fine, but I...

linux - running a process and tailing a file simultaneously

bash,shell,tail
I want a run a long task on a remote machine (with python fabric using ssh). It logs to a file on the remote machine. What I want to do is to run that script and tail (actively display) the log file content until the script execution ends. The problem...

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

bash,shell,unix,scripting,rsync
I wrote a simple script that searches through a specific directory defined by the variable "SCOPE" producing a list of directories that were modified within the past 24 hours printing them to a temp file. The first line of the file is deleted (to exclude the root level of the...

Sqoop Export with Missing Data

sql,postgresql,shell,hadoop,sqoop
I am trying to use Sqoop to export data from HDFS into Postgresql. However, I receive an error partially through the export that it can't parse the input. I manually went into the file I was exporting and saw that this row had two columns missing. I have tried a...