w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » BASH » Page 1
Bash script to recognise archive format and extract files from archives not working
Try replacing file $plik | grep 'zip' | wc -l with file $plik | grep 'zip' The exit code of grep tells you whether there is at least one matching line or not. If you pipe this to wc -l you will always get a successful result, because the string '0' represents success. Of course you have to replace all occurences of | wc -l.

Categories : Bash

Bash - Remove the last character of the line this before?
This perl command line can handle this: perl -0pe 's/,(?= ), )//g' file DROP TABLE IF EXISTS attribute_type; CREATE TABLE attribute_type ( attribute_type_id int(11) NOT NULL, name varchar(30) COLLATE es_CO.UTF-8 NOT NULL, description text COLLATE es_CO.UTF-8, is_set smallint(6) DEFAULT NULL ), DROP TABLE IF EXISTS attribute_type_options; CREATE TABLE attribute_type_options ( attribute

Categories : Bash

bash script retrive dbus output
array=($(dbus-send --session --print-reply --dest="com.ac.comp" /com/ac/comp/Time com.ac.comp.Time.GetTime)) Maybe somewhere here what you are after: echo "Seconds = ${array[7]}" echo "Minutes = ${array[9]}" . .

Categories : Bash

Scripting access to a website using different ips
There is many solutions. I think to these ones : IP spoofing. But it's not easy. In particular if you want orchestrate these tests to automate them... Another solution is to use a reverse-proxy. An example: your application is hosted by Tomcat and you use Apache as reverse proxy. In this case you can easily configure several end-points in Apache where you lie about XFF Another solution, you can

Categories : Bash

how to check killed exit bash script
A usual solution to this is, to not only rely on the existance of the file, but write the PID into it and check if the PID exists together with the file. If it does not, the PID is stale. PID=$(cat program.pid) if [ -e /proc/${PID} -a /proc/${PID}/exe -ef /usr/bin/program ]; then echo "Still running" fi (see here: http://www.odi.ch/weblog/posting.php?posting=291)

Categories : Bash

Loop through a file with colon-separated strings
You can use just bash for this: set IFS (internal field separator) to : and this will catch the fields properly: while IFS=":" read -r a b c country do echo "$country" done < "file" This returns: england sweden This way you will be able to use $a for the first field, $b for the second, $c for the third and $country for the forth. Of course, adapt the number and names to your requireme

Categories : Bash

Speed up grep and awk with gnu-parallel
Some thinkings: while IFS= read -r FILENAME do echo "Bearbeite $FILENAME ..." FILE_BASENAME=${FILENAME##*/} # no need to echo grep -v "^t=[0-9]*.[0-9]*&-$" ${FILENAME} > ${INPUT}/cleaned/${FILE_BASENAME}.tmp awk '{ if (gsub("t=|r=|i=|d=|ip=|ua=|uc=|um=|ud=|pc=|la=|lo=|do=|dm=|c=","")) print; else print}' ${INPUT}/cleaned/${FILE_BASENAME}.tmp > ${INPUT}/cleaned/${FILE_BA

Categories : Bash

Prevent expansion of `~`
You don't need to loop, you can just do: rsync -avz ~/.alias/* 'user@y:~/.alias/' EDIT: You can do: files=(.alias .vimrc) for file in "${files[@]}"; do rsync -avz ~/"${file}" 'user@server:~/'"${file}" done

Categories : Bash

SQL*Plus SPOOL on the windows command line
You have an encoding problem. First you can try to set encoding in spool part. See this question. Second you can try to choose correct encoding in Text Import wizard. That is instead of double clicking file name. Open blank excel sheet Choose Data Tab Choose Import txt file. Choose correct encoding

Categories : Bash

How to continue if expected string does not appear?
You have to use exp_continue to have an optional string in expect to wait for it. The above script can be modified as spawn apt-get install python-pip expect { "Do you want to continue" { send "Y "; exp_contine } #some other expect string along with 'exp_continue' timeout { puts "timeout happened" } eof { #some other action here# } } If expect sees those words, it will s

Categories : Bash

From bash to ksh
Your command doesn't quote $TYPE properly so it will squish any whitespace into individual spaces. Is that intentional? I'm assuming not, and changing that part of the code as well. The command will take any space in $TYPE_APACHE and replace it with \|, then pass that to sed as the regular expression for strings to remove. That can be done portably with TYPE_CANAL=$(echo "$TYPE" | sed "s/$(ec

Categories : Bash

Configure Vim/bash to open all files in separate tab when I run vim *
First of all, why don't you want to give other parameters for vim? Still you can do it like (in your .vimrc): au BufAdd,BufNewFile * nested tab sball For the second part, you can do it like: au BufAdd,BufNewFile *.o bdelete! Still for this I'd recommend to use something like a bash function like parsing the parameter list to the function and rejecting file(mask)s you don't want to edit, and

Categories : Bash

bash can a sourced script tell if a getops has been passed to parent
. child.sh has its own argument list. This means it is legal for child.sh to receive arguments in command line like this: . child.sh arg1 arg2 arg3 So, I think if you want to pass the vars, you need to do this: . child.sh "$@" --Update-- To your further question, you should write your script mimic to the one you wrote, for the getopts part, like this: while getopts "a:b:" OPTION do ca

Categories : Bash

How to redirect variable into text file then sort alphabetical
This line: echo $n | sort > out.txt always zaps the file out.txt with just the latest input. Maybe you should use: cp /dev/null out.txt # Before the loop echo $n | sort -o out.txt out.txt - The cp command creates an empty file. The sort command reads the existing file out.txt and its standard input (the new line), sorts the result and writes it out over out.txt. This is OK for short

Categories : Bash

Bash imported variables break configure script when double-quoted
Quoting the variable means the entire thing is passed as a single argument, spaces and newlines included. You want word splitting to be performed so that the string is treated as multiple arguments. That's why leaving it unquoted works. If you're looking for the "right" way to handle this, I recommend using an array. An array can hold multiple values while also preserving whitespace properly. PK

Categories : Bash

How do I tell tail -f it has finished - cleanly?
To get a full copy, use tail -n +1 -f your file If your don't use -n +1 option, you only get the tail part of the file. Yet this does not solve the deleted/moved file problem.. In fact, the deleting/moving file problem is an IPC (inter-process communication) problem, or an inter-process co-operation problem. If you don't have the correct behavior model of the other process(es), you can't res

Categories : Bash

Extract string from one line to another line and replace
This takes file input, does the substitutions, and writes to file output: awk '{if (/^CREATE TABLE/) {name=$3} else sub("table", name);print}' input >output How it works if (/^CREATE TABLE/) {name=$3} If the line starts with CREATE ALTER, then we save the third field as the name. else sub("table", name) Otherwise, we find the first occurrence of table on any line and replace it with the

Categories : Bash

Capture output of a timed out command using Ubuntu `timeout`
In my experience, this is because pipe "|" wait "echo foo; sleep 5; echo bar" run complete .So after 5s awk can get the output, but timeout terminate the command in 2s so it cannot get the text. Edit: Maybe this helps, you can move char (") to the end like this: $ cat foo.sh #!/bin/sh sh -c "echo foo; sleep 5; echo bar | awk '/foo/ {print $1;}'" $ timeout 2 ./foo.sh > foo.txt $ cat foo.txt

Categories : Bash

Bash script that executes php file every 5 seconds
You missed the & character to put the process in the background : #!/bin/bash while true do /home/user/public_html/website.com/test.php & sleep 5 done Ensure your script is eXecutable : chmod +x /home/user/public_html/website.com/test.php but to combine cron and this script, there's one way : @reboot /path/to/script.sh because you need only one instance of your script. If you c

Categories : Bash

Script to rename photos with exif
A solution to get the date with your format : $ exiftool -d %Y%m%d_%H%M%S image.png | awk -F': ' '/File Modification Date/{print $2}' Output : 20140429_110955 Start beginning a script ! #!/bin/bash dir_photo=(*.jpg) for N in ${dir_photo[@]}; do date_str=$( exiftool -d %Y%m%d_%H%M%S $N | awk -F': ' '/File Modification Date/{print $2}' ) print "$N $date_str"

Categories : Bash

Getting latest version from a Newline delimited list in BASH
Another approach (I use a proper XML/HTML parser) : get_latest() { local url="$1" local name="$2" printf '%s ' $(xmllint --html --xpath "//a/@href[contains(., '$2')]" $url) | sort -V | awk -F'"' 'END{print url$2}' url=$url } get_latest 'http://downloads.puppetlabs.com/mac/' 'facter' Output : http://downloads.puppetlabs.com/mac/facter-2.3.0.dmg Note : xmllint comes with l

Categories : Bash

Awk script Can I assign a variable if a condition using awk command is met?
Instead of using functions, you should create some scripts that can be callable from within awk. I don't think you can use bash function like this. See http://unix.stackexchange.com/questions/72935/using-bash-shell-function-inside-awk

Categories : Bash

mutt: reply email from console
You need to add the In-Reply-To: header, and the value will be the message-id of the original email. I think you'll do this (untested) echo "content" | mutt -s "Subject" -e 'my_hdr In-Reply-To: <abc123@example.com>' -- recipient@example.com

Categories : Bash

BASH: Print Nth Letter From Beginning
You can use this awk: awk -v n=3 '{gsub(/ +/, ""); print substr($0, n, 1)}' file Testing: s='re set' awk -v n=3 '{gsub(/ +/, ""); print substr($0, n, 1)}' <<< "$s" s s='He llo' awk -v n=3 '{gsub(/ +/, ""); print substr($0, n, 1)}' <<< "$s" l s='1 2 345' awk -v n=3 '{gsub(/ +/, ""); print substr($0, n, 1)}' <<< "$s" 3

Categories : Bash

trying to add an if else statement to ask user wether or not a compression must be added
Yes, you're very close. See amendments to your code echo *******Custom Backup Program******* echo echo ":Option 1: Create a backup" echo ":Option 2: Exit backup program" echo -n "Enter your choice 1, 2 : " read choice case $choice in 1) echo "perform a backup" echo "Enter full path for backup" read filepath echo " Enter destination" read location

Categories : Bash

bash script check input argument
It is different because $# in first if refer to the number of arguments to the shell script. Where as the $# in second indicates the number of argument to GetTime function To understand more I have modified the GetTime function as #!/bin/bash echo "*** Test ***" echo echo $# echo $* function test1(){ echo "test" } if [ "$#" -ne 1 ]; then echo "Illegal number of parameters" else tes

Categories : Bash

How to start a large number of quick jobs in Bash
You may want to have a look at parallel, which you should be able to install on Cygwin according to the release notes. Then running the tasks in parallel can be as easy as: parallel /Prod {} < jobs.lst See here for an example of this in its man page (and have a look through the plethora of examples for more about the many options it has). To control how many jobs to run at a time use the -j

Categories : Bash

Assignment of variables with space after the (=) sign?
This syntax assigns the empty value for the duration of the command. PWD=ick echo "$ick" This assigns PWD for the remainder of the script. PWD=ick pwd echo "$PWD" This assigns PWD only for the duration of the pwd command; the echo will echo the value which was in effect before and after the pwd invocation. PWD= This simply assigns the empty value to PWD.

Categories : Bash

How can I wait for a file to be finished being written to in shell script?
You need the wait command. wait will wait until all sub-processes have finished before continuing. parent.sh: #!/bin/bash rm output.txt ./child.sh & # Wait for the child script to finish # wait echo "output.txt:" cat output.txt child.sh: #!/bin/bash for x in $(seq 10); do echo $x >&2 echo $x sleep 1 done > output.txt Here is the output from ./parent.sh: [sri@

Categories : Bash

Bash script to read EXIF, rename JPG files and check output if file exit -> create newfile-01.jpg
Before: mv "$s" "$NEWFILE" use something like: PADDING=2 echo "New filename: " NEWFILE="$BASEDIRECTORY$x" if [[ -f $NEWFILE ]]; then BASE=`echo $x | sed "s/.jpg/_/"` LAST=`ls -1 $BASEDIRECTORY | grep $BASE | sort -r | head -1` LASTNUM=`echo ${LAST:${#x}-3:$PADDING} | sed "s/^0*//"` let LASTNUM=LASTNUM+1 FINAL=$BASE$(printf "%0"$PADDING"d.jpg" ${LASTNUM}) NEWFILE=$B

Categories : Bash

How to use the case command inside of a getopts while loop, UNIX
As has been said, options that require a value need a colon while getopts uf:n: user # ^ # / # notice --- Example

Categories : Bash

How to combine two lines from the bash prompt?
Output of "curl" contains "return" i.e. character(s) which will cause that behaviour. curl -sD - -o /dev/null -A "Mozilla/4.0" http://site/ | tr -d ' '| sed -e '/Server/p' -e '/Location/!d' | paste - - tr -d ' ' filters out all carriage return characters. About line ends While Linux/Unix uses "LF" (Line Feed, ) line ends many other systems use "CR LF" (Carriage Return Line Feed ) line

Categories : Bash

Bash script to find like lines in column 1 between two files and output to two new files
With GNU grep: grep -f <(grep -oP '^".*?"' file2.txt) file1.txt Output: "Austin, TX",123,1234,12345 "Charlotte, NC",123,1234,12345 grep -f <(grep -oP '^".*?"' file1.txt) file2.txt Output: "Austin, TX",abc,dbas,woeij "Charlotte, NC",abc,dbas,woeij

Categories : Bash

Can't break out of innermost while loop -- Bash - Ubuntu
This can be done without the need of checksums. # INITIALIZE VARIABLE FOR LOOP CHECK=`pgrep ffmpeg` I=0 while [[ "$CHECK" -gt "$I" ]]; do sleep 2 echo FFMPEG RUNNING # get the current file list ls -1 $AVIDIR/*.jpg | sort > $TMPFILE # compare current file list with previous list and extract new file list comm -23 $TMPFILE $TMPFILE2 > $NEWFILES # process new

Categories : Bash

BASH grep with multiple parameters + n lines after one of the matches
Try following: ... | telnet ... > <file> grep -e 'Subject:' -e 'Date:' <file> && grep -A50 -e 'Message:' <file> Will need to dump the output to a file first. This can be done with awk as well, without the need for dumping output to a file. ... | telnet ... | awk '/Date:/ {print}; /Subject:/ {print}; /Message:/ {c=50} c && c--'

Categories : Bash

AWK: parsing arguments in a loop
You don't need to loop over the params, pass all of them to awk with -v option: awk -v v1=$2 -v v2=$3 -v v3=$4 '{print $v1, $v2, $v3;}' $1 You may want to perform additional checks such as whether the file ($1) contains enough fields, the file ($1) exists etc. But the idea is the same. In your code, you are reading the file multiple times, each checking for only a particular field but to get y

Categories : Bash

Bash: expand variables, but not special characters
Default field separator in bash is a space so set input file separator as a new line like IFS=$(echo -e ' ') before executing eval echo $(cat expect.piece) . Final script would be : #Storing original field separator in variable OFS OFS=$IFS #Setting IFS as new line using echo -e. Unfortunately IFS=" " does not work in bash IFS=$(echo -e ' ') eval echo $(cat expect.piece) #Resetting the field s

Categories : Bash

Nectcat end connection
That's normal: netcat reads until end of input on one side, and writes until end of connection. It is designed like this. If you want to transfer several file, use a protocol intended for this: sftp, scp, rsync. Another way is to use tar and netcat. On the receiving end do: $ nc -lv $port | tar xvfz - and on the sending end do: $ tar cfz - * | nc $host $port

Categories : Bash

Detailed How-to run multiple bash scripts from one bash script?
As written there are two commands. The first is: ./auth.sh -v -C start & The ampersand & signals that the command that precedes it should be run in the background. That means that the shell does not wait for that command to complete. As soon as it can, it starts the next command: ./world.sh -v -C start exit 0 Unless the first command completes very quickly, there will be a time tha

Categories : Bash




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