w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Linux XML Editing from Command Line / Shell Script
I wouldn't try to use sed to edit XML. Unless there is some constant to match on (that lets you decide if you are on a /1 or /2) it'll be hard (I would say impossible, but some sed guru will chime and and prove me wrong...) If you can't install stuff, something like an awk or perl script that lets you keep a minimum of state you work better than sed.

Categories : Xml

Assign CPU and memory to a Linux command in shell script
You can start the command with higher CPU priority by simply starting it with the nice command, like so: # nice -n -20 checkReplace test.txt The highest possible priority is -20, with the default being 0. However, unless you're running other heavily CPU intensive processes, I can't imagine increasing CPU priority of a process will help it write to disk too much faster. That depends largely on hard drive write speeds, etc.

Categories : Linux

Evaluate output of a background linux command with C++ or Bash/Shell Script
If you run the command as shown, all output will go to stdout and display on the terminal. To capture the output you have a few options: Pipe the output to your monitor program, as in iw events | yourmonitorprogram which then reads stdin. iw should probably be modified to use unbuffered output. Write the output of iw to a file and then use the same technique as the tail -f command to poll the file periodically Have iw write to a named pipe or socket and have your monitor program read from that pipe or socket. This option requires modification to iw. The simplest option is the first one

Categories : C++

How to Create zip file in PHP using shell command on linux server
The syntax is incorrect. Try zip foo abc.doc xyz.doc or zip -r foo abc.dox xyz.doc depending upon whether you intend to replace the existing archive or not. See man zip for more.

Categories : PHP

Adding a shell script to be executed with the 'mrt/meteor create' command in terminal
Great question Johann! Alright, so to turn a shell script into something as convenient as a terminal command, all you need to do is create an alias for that script in your terminal's rc file. Further instructions as to how you can do that can be found here. So all you need to do is list out the commands you want automated in the shell script, including the meteor/mrt commands, and pass the directory/project name with the special variable "$1" passes the first argument after your command into your script. Here's the script I am currently using, which implements the folder structure from Discover Meteor and adds coffeescript and stylus-mixins There are probably some redundancies in commands. Let me know if you see anything that can be cleaned!

Categories : Shell

Translating shell script into Windows command shell script (batch)
for /L makes a count-controlled loop in batch. mkdir remains mkdir. @echo off for /L %%y in (1,1,9) do mkdir week_0%%y mkdir week_10

Categories : Shell

Create output file names based on input file name with autonumbers shell script linux
VAR="INPUTFILENAME" # One solution this does not use the VAR: touch INPUTFILENAME{1,2,3,4,5,6,7,8,9,10} # Another for i in `seq 1 20` ; do touch "${VAR}${i}" done And there are several other ways.

Categories : Linux

Similar command to linux tree command in adb shell
You need to install busybox for android, it will add many well known linux tools to your phone. You need a rooted phone for installing busybox. Check it out here: https://play.google.com/store/apps/details?id=stericson.busybox&hl=fr

Categories : Linux

Shell command works in shell but not in shell script
You are using single quotes in this command: filelist=$(grep '$incstring' -rl --include=*.{h,cpp} pathToFiles) Single quotes inhibit variable expansion. That is, you're looking for the literal string $incstring rather than the contents of that variable. This command, as shown here, would not have worked on the command line either. From the bash(1) man page: Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash. Replace the single quotes with double quotes: filelist=$(grep "$incstring" -rl --include=*.{h,cpp} pathToFiles)

Categories : Shell

Running two node servers from a single shell command using a shell script
Your command does not work because you are trying to have two processes running in the same shell. Instead, you should 'spawn' the node processes into different processes. Try this command: node project/rest.js & node static-server.js &

Categories : Node Js

How do I run the same linux command in more than one tab/shell simulataneously?
Why not do something like for i in {1..100} do ./myprog argument1 argument2 & done This is in case the shell is bash. You can look into other looping constructs in case of other shells.

Categories : Linux

Error about the tr command of linux shell
Yes, that's exactly what it means. '9-0' isn't a range, anymore than 'z-a' is a range. Otherwise, how does it know whether you mean 0-9 or the entire unicode range starting from 9, going to the top of the range and wrapping around back to 0?

Categories : Linux

How to give o/p of one command to the argument of another command in shell script?
As per what i think the below code should satisfy your need. I only gave a dry run to it. Store the result in a variable and then looping to extract data one by one #! /bin/bash $op = find ./kernel -name *.ko" for zf in $op do cp -rpf $zf tail $zf done

Categories : Linux

bash shell script error works on command line, not in script
Variables are supposed to contain data, and bash treats them as data. This means that shell meta-characters like quotes are also treated as data. See this article for a complete discussion on the topic. The short answer is to use arrays instead: ASCIIDOC_OPTS=( --asciidoc-opts='-a lang=en -v -b docbook -d book' ) DBLATEX_OPTS=( --dblatex-opts='-V -T db2latex' ) cmd=(a2x -v -f pdf -L "${ASCIIDOC_OPTS[@]}" "${DBLATEX_OPTS[@]}" "$1".asciidoc) # Print command in pastable format: printf '%q ' "${cmd[@]}" printf ' ' # Execute it "${cmd[@]}" Make sure not to use eval: eval "$cmd" #noooo This will appear to work with your code as you posted it, but has caveats and security problems.

Categories : Bash

The DB2 SQL script is hanging in shell script, but working successfully in command line
Are you sure DB2 is blocking? Did you put a semicolon between commands db2 CONNECT TO ktest4 ; db2 -v -f /tmp/sql/application_system/opmdb2_privilege_remove.sql.5342 In order to trace the execution, I advise you to put some output, in order to detect where is it blocking date ; db2 -r /tmp/output.log CONNECT TO ktest4 ; db2 -r /tmp/output.log values current timestamp ; db2 -r /tmp/output.log -v -f /tmp/sql/application_system ; db2 -r /tmp/output.log values current timestamp ; db2 -r /tmp/output.log terminate With a command like this, you will save all outputs, and then you could check where is the error.

Categories : SQL

Linux Shell, display something while a command is running in the background
Whiptail is a tool to do this for you. It is fairly easy to make it display a progress bar, or other information, for you, while your task completes. In fact, it's the tool used by Debian, and many other distributions, in exactly the same context you're using. Here's a simplified version of the code we use to make aptitude installs friendlier looking: pkg=0 setterm -msg off # Disable kernel messages to this terminal setterm -blank 0 # Disable screen blanking aptitude -y install <list of packages> | tr '[:upper:]' '[:lower:]' | while read x; do case $x in *upgraded*newly*) u=${x%% *} n=${x%% newly installed*} n=${n##*upgraded, } r=${x%% to remove*} r=${r##*installed, } pkgs=$((u*2+n*2+r))

Categories : Linux

Convert Linux shell script for Mac OS X
You may want to install core-utils from brew (The missing package manager for OS X) and then use gsplit: $ brew install coreutils $ gsplit --help Usage: gsplit [OPTION]... [INPUT [PREFIX]] Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default size is 1000 lines, and default PREFIX is 'x'. With no INPUT, or when INPUT is -, read standard input. Mandatory arguments to long options are mandatory for short options too. -a, --suffix-length=N generate suffixes of length N (default 2) --additional-suffix=SUFFIX append an additional SUFFIX to file names. -b, --bytes=SIZE put SIZE bytes per output file -C, --line-bytes=SIZE put at most SIZE bytes of lines per output file -d, --numeric-suffixes[=FROM] use numeric suffixes instead of alphabetic.

Categories : Osx

Same shell script has different behaviour on different Linux distributions
In Ubuntu, the default shell /bin/sh is a symbolic link to /bin/dash - bash and dash have enough functionality in common that most people never realize the difference, but they are not identical (dash is meant to be lighter). The Debian Almquist shell (dash) is a Unix shell, much smaller than Bash, but it is still aiming at POSIX-compliance. It requires less disk space, but it is also less feature-rich. - Wikipedia You should be safe while sticking to POSIX syntax, but if your script is using features that are only available in bash, be sure to change the shebang from /bin/sh to /bin/bash to avoid trouble with systems where /bin/sh is not bash. So my advice is: never assume bash is the default shell, stick to syntax from the POSIX standard if you can or explicitly point to /bin/bash

Categories : Linux

Linux Shell-Script code is not executing as it should
Two things that are wrong in your program: Line No. 8 - You are calling your array arr[] but later referring it as a[] . Change one of the names to match the other. Line No. 10 - There is no $n in your program. You mean $size. Change this as well. I think your program should work after this.

Categories : Linux

Linux shell script not giving any output
Your command: for i in cat list; do echo $i; done Will just print cat and list as output. If you just want to run for loop for each line of file list then use: while read l do echo "$i" # repalce echo with your actual script commands and keep "$i" in double quotes done < list

Categories : Bash

Copy a variable in shell script (Linux)
Note that cp is used to copy files and directories. To define variables, you just have to use the following syntax: v=$1 Example $ cat a echo "var v=$v" v=$1 echo "var v=$v" $ ./a 23 <---- we execute the script var v= <---- the value is not set var v=23 <---- the value is already set

Categories : Linux

Renaming files in Shell Script Linux
You don't need to rename the file if you use wget's -O option: #!/bin/bash [ -n "$BASH_VERSION" ] || { echo "You need Bash to run this script." exit 1 } while IFS=$' ' read -a INPUT; do wget -O "${INPUT[0]}_${INPUT[2]}.bam" "ftp://hgdownload.cse.ucsc.edu/goldenPath/hg19/encodeDCC/${INPUT[1]}/${INPUT[3]}" done < input_list.txt Make sure you save the file in UNIX file format like script.sh and run bash script.sh.

Categories : Linux

Shell script linux, validating integer
Analyse this regex: '^(+|-)?[0-9]+$' ^ - Line Start (+|-)? - Optional + or - sign at start [0-9]+ - One or more digits $ - Line End Overall it matches strings like +123 or -98765 or just 9 Here -E is for extended regex support and -q is for quiet in grep command. PS: btw you don't need grep for this check and can do this directly in pure bash: re='^(+|-)?[0-9]+$' [[ "$character" =~ $re ]] && echo "its an integer"

Categories : Regex

Pass all parameters of one shell script to another
You need to say: Test2.sh "$@" Refer to Special Parameters: @ Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" .... If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. When there are no positional parameters, "$@" and $@ expand to nothing (i.e., they are removed). The manual says: "$*" is equivalent to "$1c$2c...", where c is the first character of the value of the IFS variable. which explains the result you're observing.

Categories : Shell

Executing a Linux command (mutt) on java shell not working properly
This is a good tutorial on how to use Runtime.exec When Runtime.exec() won't. The idea is that you need to consume the standard input, output and error for the process created by Runtime.exec and the site i mentioned is perfect.

Categories : Java

Quickly accessing file names listed by the ls command on Linux shell
Use wildcard expansion, i.e. for the second file: vim *v04*41* or, if your shell supports it, tab-completion: type vim M; press [Tab], that completes all up to next difference, i.e. OD11A1.A2012193.h12v0; type 4; press [Tab], and so on.

Categories : Linux

How to get result from background process linux shell script?
I finally found a working solution using anonymous pipes and bash: #!/bin/bash # this executes a separate shell and opens a new pipe, where the # reading endpoint is fd 3 in our shell and the writing endpoint # stdout of the other process. Note that you don't need the # background operator (&) as exec starts a completely independent process. exec 3< <(./a.sh 2&1) # ... do other stuff # write the contents of the pipe to a variable. If the other process # hasn't already terminated, cat will block. output=$(cat <&3)

Categories : Linux

Linux Shell-Script And Recursion, Variable not retaining value
The problem is this line: lastfib=$c It should be: lastFib=$c # ^ # Capital F Variable names in bash are case-sensitive.

Categories : Bash

Windows executable with linux shell script inside
A Linux shell script should start with #!. A Linux ELF executable should start with x7FELF. If a Windows executable cannot start with these bytes your dream is not possible. I believe that PE (the binary format of Windows executable) cannot start with these (but I am not sure). Hence your universal installer single file is an impossible dream. On Linux, you could consider playing with binfmt_misc or shar. Read Levine's Linkers and Loaders book, and elf(5) & execve(2) Linux man pages.

Categories : Linux

run shell script in program and input parameters
I didn't remember exactly what the command was called, but it exists! Now, I have found it. The expect command will wait for a prompt like the one you have described, and then it will pretend to be a keyboard and it will enter data. A quick example: #!/usr/bin/expect set timeout 20 spawn "./parse" FOLDER="/x/y/z" LOGIN="Randy" PASSWORD="horse_stapler" PROJECTID="136729" expect "parse new " { send "$FOLDER" } expect "Login>" { send "$LOGIN" } expect "Pw>" { send "$PASSWORD" } expect "projectID>" { send "$PROJECTID" } interact ... more examples like this one here. BUT WAIT. There are 2 things that you need to know. Firstly, The reason that the top of the script is "#!/usr/bin/expect" is because this is not bash. Instead this is it's own special kind of script. Read mor

Categories : Shell

How to trigger a certain shell script on multiple Linux machines simultaneously?
If you're using bash as your shell, you should include a tag for it. (Note the relatively low number of 'followers' for your tags.) Assuming a modern Linux/Unix shell, the answer to you question is to append the & character to the line that makes the connection to the remote machine. & means 'run this process in the background'. So something like #!/bin/bash # master script ssh host1 "/path/to/remote/script/runMe" & ssh host2 "/path/to/remote/script/runMe" & ssh host3 "/path/to/remote/script/runMe" & ssh host4 "/path/to/remote/script/runMe" & Sounds like what you are looking for. Capturing log information and monitoring the status of the remote "runMe"s is in the realm of consultation engagments or at least 100 hrs of experimentation on your part. Good luck

Categories : Linux

Trying to translate a linux shell script loop to Windows + GnuWin32
Try this: for /f "delims=" %%A in ('cat "%~1" ^| sed "s/.*,//g" ^| sort -u') do (some stuff with %%A) In Windows replace the single quotes from linux shell script ' with double quotes ". If you need double quotes in GNUWin commands, it must be escaped by a backslash - but only on the Windows shell prompt cmd, the scripts from sed, awk etc. are fully compatible.

Categories : Shell

wait command in shell script
If the process ID is, for example, 42 then your wait instruction becomes: wait [42] which is not what you want - the square brackets are a problem. It should be: wait $pid as per the following transcript: pax> date ; sleep 60 & Wednesday 17 July 10:43:51 WST 2013 [1] 5200 pax> pid=$! ; echo $pid 5200 pax> wait [$pid] bash: wait: '[5200]': not a pid or valid job spec pax> wait $pid ; date [1]+ Done sleep 60 Wednesday 17 July 10:44:51 WST 2013 And, just as an aside (irrelevant to the answer), wait() is better suited to the C wait() function. If you're using wait from the shell, you would normally leave off the parentheses.

Categories : Bash

Python script to run shell command
Why are you using subprocess? A common practice to run Scrapy from a script is to use twisted's reactor. Taken from docs: from twisted.internet import reactor from scrapy.crawler import Crawler from scrapy.settings import Settings from scrapy import log from testspiders.spiders.followall import FollowAllSpider spider = FollowAllSpider(domain='scrapinghub.com') crawler = Crawler(Settings()) crawler.configure() crawler.crawl(spider) crawler.start() log.start() reactor.run() # the script will block here There is plenty of examples out there: Running scrapy from script (beginner) How to run Scrapy from within a Python script Running Scrapy from a script - Hangs Scrapy crawl from script always blocks script execution after scraping Hope that helps.

Categories : Python

Linux Bash Shell Script: How to "ls" a directory and check some output string?
To check for a directory: if [ ! -d '/var/aaaaaaa' ]; then echo 'no dir!' fi For file: if [ ! -f '/var/aaaaaaa' ]; then echo 'no file!' fi To check output: if ls '/var/aaaaaaa' 2>&1 | grep 'No such'; then echo 'no such'; fi To check when ls fails: if ! ls '/var/aaaaaaa' &> /dev/null; then echo 'failed' fi

Categories : Linux

Linux Shell Script: How to detect NFS Mount-point (or the Server) is dead?
"stat" command is a somewhat cleaner way: statresult=`stat /my/mountpoint 2>&1 | grep -i "stale"` if [ "${statresult}" != "" ]; then #result not empty: mountpoint is stale; remove it umount -f /my/mountpoint fi Additionally, you can use rpcinfo to detect whether the remote nfs share is available: rpcinfo -t remote.system.net nfs > /dev/null 2>&1 if [ $? -eq 0 ]; then echo Remote NFS share available. fi Added 2013-07-15T14:31:18-05:00: I looked into this further as I am also working on a script that needs to recognize stale mountpoints. Inspired by one of the replies to "Is there a good way to detect a stale NFS mount", I think the following may be the most reliable way to check for staleness of a specific mountpoint in bash: read -t1 < <(stat -t "/my/m

Categories : Linux

Passing multiple parameters from shell script to mysql query
assuming you call the script like this $ ./script param1 param2 param3 in the script echo $0 #will echo 'script' (the name of the script) echo $1 #will echo 'param1' echo $2 #will echo 'param2' echo $3 #will echo 'param3' echo $# #will echo '3' the number of params passed to script echo $@ #will echo 'param1 param2 param3' (all the parameters passed) host="127.0.0.1" user="root" password="pass" result=`mysql -h $host --user=$user --password=$password --skip-column-names -e "select $param1 from $param2 where $param3 = 3"` echo $result

Categories : Mysql

Shell script array from command line
This tcl script uses regex parsing to extract pieces of the commandline, transforming your third argument into a list. Splitting is done on whitespaces - depending on where you want to use this may or may not be sufficient. #!/usr/bin/env tclsh # # Sample arguments: 1 2 {element1 element2} 4 # Split the commandline arguments: # - tcl will represent the curly brackets as { which makes the regex a bit ugly as we have to escape this # - we use '->' to catch the full regex match as we are not interested in the value and it looks good # - we are splitting on white spaces here # - the content between the curly braces is extracted regexp {(.*?)s(.*?)s\{(.*?)\}s(.*?)$} $::argv -> first second third fourth puts "Argument extraction:" puts "argv: $::argv" puts "arg1: $first" puts "arg2: $s

Categories : Arrays

Script Shell - Command nohup - "&" - Doubts
nohup means "no hangup", meaning that the process will still run after you log out of the shell. The amptersand & means the process will run in the background and so you'll get back to your shell prompt after you run that command. The -Dprocess is a Java property being passed in to the Java program with the environment variable PROCESS. Likewise, the classpath is being set to the environment variable CLASSPATH. The Java class with the public static void main method is batch_wtq, which should be on the classpath somewhere.

Categories : Shell

Rescue ruby command in shell script
to run system commands within ruby, you can do the following: system 'twurl -t -d track=keyword -H stream.twitter.com /1.1/statuses/filter.json' this gives you the global variable $? for the exit status of the process which should be 0 if the process didn't succeed. so your ruby script would be something like: system 'twurl -t -d track=keyword -H stream.twitter.com /1.1/statuses/filter.json' if $? == 0 #retry, throw exeption, etc. end you can also use backticks to run the command and get output status. the following may work for the timeout error. output=`twurl -t -d track=keyword -H stream.twitter.com /1.1/statuses/filter.json` ; result=$?.success?

Categories : Ruby



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