New answers tagged

0

If you really reluctant about writing scripts you may find Here document handy. Short said, you add << SOMETEXMARKER to the end of the line and continue entering as many commands for remote host as you like. Then, on the last line you enter (at the very beginning of the line) the same SOMETEXTMARKER and that makes the entered commands get executed ...


2

It might be easier to simplify the command so that you have fewer special characters on which the shell might choke: ssh jboss@myTargetServer 'ps -p $(cat /var/run/jboss-as/jboss-as-standalone8.pid) -o %cpu= 2>/dev/null' The trailing 2>/dev/null throws away the error text in the event that the PID file either cannot be found or contains a stale PID. ...


1

The second command as you have it runs the code part ($()) in local subshell. You need to make it run on the other side by escaping special characters (basically $): ssh jboss@myTargetServer tmpValue=\$(cat /var/run/jboss-as/jboss-as-standalone8.pid) \ && top -b -U jboss -n 1 |grep \$tmpValue |awk '{print $9}' or put it all into the apostrophes ' ...


2

I would recommend putting those commands into a script that you remotely call with ssh. Otherwise you'd need to put the whole "remote" part of the command line into quotes and properly escape everything inside. This can be tedious and error prone. That's why remote script call.


0

mv 'old.file(1).gz' new.file.gz should fix the problem.


0

I found out that the .$EXTEND directory is created on an Oracle ZFS storage system when SMB is enabled. SMB can be disabled for the pool but the .$EXTEND directory still cannot be removed.


3

You don't need the names to be quoted, you need the variables to be quoted. Specifically, to make your script work, you need to replace the for folder in ... loop with: /tmp/IMAPdedup-master/imapdedup.py -s "$SERVER" -x -u "$USER" -w "$PASS" -l | while IFS= read -r folder; do /tmp/IMAPdedup-master/imapdedup.py -s "$SERVER" -x -u "$USER" -w "$PASS" ...


0

You need to understand that the $'...' is a feature of the shell to write escaped characters. A $'\033' is an actual escape ESC. Therefore, you need to move the $' ' from inside the sed command: sed -e $'s/ *[^ ]* /\033[1;33m&\033[0m/6' To the actual variables you will use: fg_normal=$'\033[0m' fg_yellow=$'\033[1;33m' With that simple change, this ...


2

You could use: fg_normal=$(echo -e "\033[0m") fg_yellow=$(echo -e "\033[1;33m") or with tput: fg_normal=$(tput sgr0) fg_yellow=$(tput setaf 3)


0

You could use printf's %b specifier to assemble the sed command, preserving the correct backslash escape sequences: ps -eo pid,ppid,time,user,tty,%cpu,%mem,vsize,command --sort -%cpu | head | sed -e "$(printf 's/ *[^ ]* /%b&%b/6' "$fg_yellow" "$fg_normal")"


4

You're not actually running a bash command. What you're doing is running an executable directly and passing it arguments. Try the following script to see what is happening: import subprocess p = subprocess.Popen(["echo", "a", "b", "|", "rev"], stdout=subprocess.PIPE) print p.communicate() The output will be: ('a b | rev\n', None) There's no ...


0

You cannot split() your command string as it contains characters that need to be processed by the shell, eg ~ and |. Use the version: process = subprocess.Popen(my_command, stdout=subprocess.PIPE, shell=True)


2

To differentiate a variable from a string bash uses $. When you do : rm -R .$EXTEND variable $EXTEND is expanded and the result is substituted. Inorder to remove .$EXTEND file you need to tell bash to interpret $ without its special meaning. You can do it two ways : rm -R .\$EXTEND #\ strips the special meaning of $ or rm -R '.$EXTEND' # Use single ...


4

You can either escape the $ sign: rm -r .\$EXTEND or use single quotes: rm -r '.$EXTEND'


1

One example: $ echo jeff > jeff $ echo not > not $ echo 's/jeff/not/' | sed -i -f - * $ cat jeff not For more information on what standard shells should do with filename/pathname expansion (globbing), see: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_06 where it says: After field splitting, if set -f is not ...


0

You don't need xargs at all. As I read elsewhere on this site (sorry, can't recall just where) from a top user: Yes, xargs is a cool toy. No, you don't need to use it. This: ls * | xargs -I {} sh -c 'echo {}; awk '{print $1}' {} | uniq' Can be fully replaced with this: for f in *; do echo "$f"; awk '{print $1}' "$f" | uniq; done This gives you ...


0

You have two main problems: piping ls * into xargs is just plain wrong. It will break if any of the filenames contain spaces, newlines, shell globbing characters, or (depending on what you're running with xargs) if they begin with a -. use find ... -print0 | xargs -0 instead. Nested quotes. As @Gilles mentions in his answer, there are ways of doing this ...


1

The second single quote terminates the first single-quoted string 'echo {}; awk '. Then {print $1} is unquoted, and then there is another single-quoted string ' {} | uniq'. This should be clear in any editor with syntax highlighting; it's also clear if you look at the syntax highlighting in your question. Here the simplest approach would be to avoid nested ...


-1

The embedded date command will only be evaluated once: when the alias is created. That's the reason reloading the .zshrc makes it work again. If you use a function instead as djf suggested, it will be evaluated every time which seems to be your intended behavior.


2

Backquotes delimit a command substitution: the command inside the backquotes is executed, and its output is interpolated into the command line. (There are further complications if the backquotes are not inside double quotes, more on this later.) So what's happening is that git rev-list … is executed in the current directory, before RepoScan runs. It can't be ...


5

When you write $PGWA without quotes, this splits the value of PGWA at whitespace¹. Quote characters have no special meaning there, so you end up with the words -o, ProxyCommand="ssh, gateway1, nc, %h and %p". See Why does my shell script choke on whitespace or other special characters? for more explanations. A variable expansion outside of double quotes is ...


3

Your line: psql -U postgres -d ebay_sold -c "UPDATE test_table SET title = regexp_replace(title, '"', '', 'g')" is the problem. You open a double-quoted string at "UPDATE, but it is closed earlier than you think it is, causing you to attempt to run the following as SQL: UPDATE test_table SET title = regexp_replace(title, ' This is clearly not valid. ...


0

I was skeptical of Stéphane’s answer, however it is possible to abuse $#: $ set `seq 101` $ IFS=0 $ echo $# 1 1 or $?: $ IFS=0 $ awk 'BEGIN {exit 101}' $ echo $? 1 1 These are contrived examples, but the potential does exist.


1

So it seems like there are extra quotes being inserted around the contents of noquotes.txt, but not around quotes.txt. This is just Bash being helpful. You'll notice it will put quotes around things whenever there's a symbol that would otherwise be interpreted by Bash. It acts just like you would, using quotes only when necessary. Try to put any of the ...


29

There are two problems with your example. The primary one is that you're assuming that regular expressions work the same as glob patterns in that * is a wildcard meaning "any sequence of characters." In regular expressions, * means "any number of the previous atom" instead, so fil* means f followed by i followed by zero or more l characters. You need to say ...


1

The line in your code weka $1 ${search["$1"]} is being subject to shell spliting. If you have not changed the variable $IFS that splitting will happen on spacetabnew line. The line gets expanded to: weka $1 ${search["$1"]} weka a -search "a params" -search "other a params" But getting split as described above, this is what it means: <weka> ...


1

The shell does not handle quoted quotes the way that you want. (Once the quotes are quoted, they are treated like regular characters.) You can trick bash into doing what you want. To start define an associative array: declare -A s s=( ["a"]='-search;a params;-search;other a params;' ["b"]='-search;just these params' ) As you can see, the string has the ...



Top 50 recent answers are included