Tag Info

New answers tagged

0

I had a similar requirement - I needed to use ksh93 on AIX 5.3 to support associative arrays. So I set up the script to start a second instance using ksh93. I also added a safeguard to keep it from respawning itself over and over. #!/bin/ksh scr=$0 safe=$1 echo "Check OS to determine if ksh93 is needed..." if ( `typeset -A testvar > /dev/null ...


1

There is a " missing at the end of line 5.


2

You refer to a hostname variable. The construct you're using, ThisHost=$(hostname), is calling the hostname command. Since the value is empty, it then becomes a question of why your system doesn't know its name. (You can confirm this by typing hostname by itself and seeing that your system has no name.) According to a RPi forum posting The hostname should ...


0

There isn't really any such thing as a guaranteed set of directories to include in PATH. You'll find /bin but everything else is just probable or possible. Users on my systems will have something like $HOME/bin:/usr/local/bin:/bin:/usr/bin. Root users would have /usr/local/sbin:/sbin:/usr/sbin in there too. If your file might be in one of a number of places ...


0

It appears from my research that it cannot be done without some very extensive coding. There needs to be some sort of macro or api system setup which interacts with dropbox's site to add each new dropbox client (server) to the list of allowed clients on the dropbox account in order for you to install the daemon. What happens is the daemon runs and then gives ...


0

The interactive shell loads .bashrc, the script doesn't. If your $PATH is set in .bashrc and you don't export it, the script doesn't inherit your modifications to $PATH. If you call export PATH, the script should see it. Check export -p to see what variables get exported ($PATH should be among them). Also check $BASH_ENV which could potentially override your ...


5

If you have GNU Parallel you can do this: parallel do_it {} --option foo < argumentlist GNU Parallel is a general parallelizer and makes is easy to run jobs in parallel on the same machine or on multiple machines you have ssh access to. If you have 32 different jobs you want to run on 4 CPUs, a straight forward way to parallelize is to run 8 jobs on ...


0

You can, but it's tricky and fragile. There are several options, one of them is xargs. The problems encountered when relying on job control and signals are discussed in this interesting article, really a recommended read: http://prll.sourceforge.net/shell_parallel.html The guy apparently made a new tool prll that can take arbitrary shell functions to ...


2

If your system supports zsh command, then in bash script you can run zsh -c 'ls -lhS -- **/*(.D)' This probably requires some explanation: zsh: other than bash, more powerful shell with a lot of features -c: take next argument as a command to execute by zsh ls -lhS: according to your question this is the command you want to execute --: takes care of ...


2

If your find supports it, you can use %s in -printf ("File's size in bytes"). If your sort supports nul-delimited input (-z), you can then do: find . -type f -printf "%s %f\0" | sort -nz | tr '\0' '\n'


3

Basic example of sed usage using this as test.txt: one two three two four two five To replace two with foo in that file: sed -i 's/foo/two/g' test.txt What that means: sed is the name of the command, you'll find lots of tutorials (e.g.) and other documentation online, in addition to man sed. -i means edit a file in place. 's/foo/two/g': the s ...


1

dpkg --print-architecture will output the primary architecture of the machine it's run on. This will be armhf on a machine running 32-bit ARM Debian or Ubuntu (or a derivative), arm64 on a machine running 64-bit ARM. Note that the running architecture may be different from the hardware architecture or even the kernel architecture. It's possible to run ...


1

super [ -r reqpath] command [ args ] Super allows specified users to execute scripts (or other commands) as if they were root; or it can set the uid, gid, and/or supplementary groups on a per-command basis before executing the command. It is intended to be a secure alternative to making scripts setuid root. Super also allows ordinary users ...


0

Don't use alias. Use a shell function. Like this function sysctl_start { systemctl start "$1" && echo SUCCESS || echo FAILURE } or even better function sysctl_start { systemctl start "$1" systemctl status "$1" } If you want just special handling for start, but keep the name, write a wrapper function systemctl { if [ "$2" = ...


2

When you type function_under_test, the shell think it's a command, not a variable. You need to expand it, so function_uneder_test will be expanded to sum_squares. Change your line 32 to: "$function_under_test" "$3"


1

Because {1..$num_in} did not expanded to sequences of numbers, it's only expanded to literal string like {1..1}, {1..2} and so on. So, your script performed arithmetic expansion, it saw an invalid number, and print error message. When you use your shebang as #!/bin/sh, it depends on system to use what shell /bin/sh linked to for running your script. Thus, ...


2

{1..$num_in} is a kshism/zshism. You should write: `seq $num_in` Note: Though bash supports code like {1..3}, as said by 1_CR in comment, {1..$num_in} doesn't work in bash, due to the fact that brace expansion precedes parameter substitution. So, it probably comes from ksh93 or zsh, where it works because parameter expansion is done first.


5

Your function has an exit status but no output. Your variable $a will always be empty, so the [[ $a ]] test will always be "false" You truly want this: if is_equal 42; then ... But what you think you want is this is_equal 42 # don't capture the output a=$? # but do grab the exit status if [[ $a -eq 0 ]]; then ...


0

According to tftp's help you can't: tftp> ? Commands may be abbreviated. Commands are: connect connect to remote tftp mode set file transfer mode put send file get receive file quit exit tftp verbose toggle verbose mode trace toggle packet tracing status show current ...


0

## implemantion of base class function Class() { base=${FUNCNAME} this=${1} Class_setCUUID $this for method in $(compgen -A function) do export ${method/#$base\_/$this\_}="${method} ${this}" done } function copyCUUID() { export ${2}_CUUID=$(echo $(eval "echo \$${1}_CUUID")) } function Class_setCUUID() { ...


1

Use here documents. tftp 10.1.0.203 << fin get /test/${ThisHost}.ica quit fin That should get /test/${ThisHost}.ica from your tftp server.


1

Using a for loop: awk '/^$/{next}; {for(i=1;i<=5;i++){printf "%s\t", $i}; printf "%.6f\n", $6*3}' file Data 9390.900391 10573.089844 80.000000 200.000000 8.100000 Data 17762.810547 18536.189453 85.000000 200.000000 8.100000


2

Try: $ awk 'NF{$NF = sprintf("%.6f", $NF*3)}1' file Data 9390.900391 10573.089844 80.000000 200.000000 8.100000 Data 17762.810547 18536.189453 85.000000 200.000000 8.100000 Change $NF to the $n where nis the field you want to change.


3

for((i=2;i<=$#;i++)); do wc "${!i}" done


1

Just calling shift with argument 1 and remember to quote "$@": shift 1 wc "$@"


3

You get an error because you're attempting to do arithmetic equality with string values. Here are 2 ways to check whether the elements of dfArray are in dsmArray set -A dfArray / /usr /var /tmp ... set -A dsmArray /home /opt /usr ... for a in "${dfArray[@]}"; do in=false for b in "${dsmArray[@]}"; do if [[ $a == $b ]]; then echo "$a is in ...


2

You can "subscript" that pseudo-array. It starts with $1, so to iterate over $2, $3, ... for arg in "${@:2}"; do echo "$arg" done


0

There is some palliative. I added keyboard shortcut to terminal (~/.bashrc), that draw some colored marker (actually, green line in my case). print_green_line() { echo "$(tput setaf 2)________________________________________$(tput sgr 0)" } bind -x '"\eG": print_green_line' # Alt+Shift+G After marker I start my long output command. Now, it's easy to ...


2

for f do exec <"$f" : handle stdin done A non-interactive shell will treat any redirection from a file that cannot be read or that does not exist when associated w/ a special builtin as a fatal error and exit immediately with a meaningful diagnostic message written to stderr. So either your parameters are valid, readable files and the above ...


0

first_file="$1" test -f "$first_file" || exit 2 file_content="$(<"$first_file")" echo "$file_content"


-1

You can do it: #!/bin/bash while read line ; echo "$line" ####### ####### ######## done < "$1" description: each $line is a content of complete line of your file. usage : ./script.sh file.txt


0

The question is not very clear, but I believe you are looking for the following construct: awk 'BEGIN{FS=OFS=","}NR==FNR{print $1,$2,"\"\"";next}{print "\"\"",$1,$NF}' success.csv error.csv Explanation: first of all at the very beginning we set field separator (FS) and output field separator (OFS) to , we process both files in one go, but we check which ...


0

I was trying since yesterday evening, Within few minutes after posting in StackExchange I found a solution. string="https://111.22.33.44:5557/xyzsess81122334442/scripts4/listaccts/xfercpanel/some" Thanks for your help... echo $string | sed 's/\//\/\n/4' > echo $string | sed 's/\//\/\n/4' > s/ -> replace command > \/ ...


0

> str1="https://111.111.111.111:2222/cpsess8993738132/scripts4/listaccts/" > rest="${str1#*//?*/}" > str="${str1%"$rest"}" > echo "$str" https://111.111.111.111:2222/


2

may try: gnome-terminal -e "bash -c 'watch sensors'" gnome-terminal -e "bash -c 'gedit /etc/hostname'" gnome-terminal -e "bash -c 'processing /home/Desktop/samudra_gui/samudra_gui.pde'" and start this script from .bashrc or write this in .bashrc


1

Edit .bashrc Or .bash_profile. http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_01.html


1

You could add a sed command after the curl command to replace commas inside numbers: cd desktop/quoteUpdate while true do curl -o quotes.txt -s "http://download.finance.yahoo.com/d/quotes.csv?s=goog,aapl&f=nsl1j2" sed -i -E 's:([0-9]),([0-9]):\1\2:g' quotes.txt echo UPDATED: date sleep 10 Done The result will look like this: "Google ...


0

It looks like you're trying to indirectly reference an array from the index of another. You might like to do something like: arr_one[0]=arr_two[@] From there you can do: cmd "${!arr_one[0]}" ...to indirectly reference a full expansion of "${arr_two[@]}". As near as I can tell, there is no direct method of indexing further. For example ...


2

So, when is it important to write portable scripts? what types of scripts should be as portable as possible? When you're using them for your working environment, and you work (or could in the future) on different machines - AND, you don't want to have to rewrite your tools prior to getting down to work. eg: a trash script / rm replacement Mark ...


1

If you need ls details use -H (--dereference-command-line) option: ls -lH ./aliasedname


0

How about using readlink? man readlink for details. E.g., [/tmp]$ ls -l lrwxrwxrwx. 1 root root 9 Jan 16 10:07 mylink -> test-link -rw-r--r--. 1 root root 0 Jan 16 10:07 test-link [/tmp]$ readlink -f mylink /tmp/test-link In response to your edit, you might benefit from "File Test Operators" -h file is a symbolic link


0

In first close it can be sed-script: sed -E ' /Mikrotik01/{s/.* ([0-9.]{7,}) .*/\1/;x;/^$/!b} /[0-9.]{7,}/!d s/.* ([0-9.]{7,}).*/\1/ x G s/\n/,/ h $!d' file.txt > file.csv Or (may be shorter a little but not so strong - it recognize new line block by | not by Mikrotik01) sed -E ' /^T/d s/^[^.]*[|:] // / \|.*$/{s///;x;/^$/!b} x G s/\n/,/ ...


1

awk -F'[[:blank:]|]+' ' /^Mikrotik01/ {if (NR>1) print ""; printf "%s", $(NF-2)} /Unique Entry/ {printf ",%s", $NF} END {print ""} ' file.txt > File.csv


1

my understanding is that the second part of your code give a PID, and you want to grep it. and also the double ps is a typo. something like while read -r -u10 server port line do echo ========== server: "$server" port: "$port" ========== pid=$(ssh -qn "$server" "netstat -tulpunt | grep -E ":$port "" | \ awk '{print $7}' | grep '/' | awk -F ...


2

This is very simple. You don't need delimiters as such, a simple regular expression will do. Just look for an opening [, followed by as many non-] or [ characters as possible until the end of the line. For example: Perl If you know there are no [[ or other strange things: perl -pe 's/\[.+?\]//g' file If you can have strange things: perl -pe ...


1

With grep: diff -c file1 file2 | grep -v '^ ' none of the other lines start with two spaces: not the ones starting with !, and not the line indications.


1

with grep: diff -c file1 file2 | grep '^[-!*]'` with sed: diff -c file1 file2 | sed '/^[-!*]/!d'


0

Assuming you meant for i in $(cat server) ..., consider using while read loop: while read host port do echo ===$host==== ssh -q "$host" 'netstat -tulpun | egrep "'"$port"'"' done < server Assuming: there are exactly two whitespace-separated entries in each line, the second entry is a valid port number


0

You should start with: #!/bin/bash cat server | while read str do server=$(echo "$str" | cut -d' ' -f 1) port=$(echo "$str" | cut -d' ' -f 2) echo server: "$server" port: "$port" ssh -q "$server" 'netstat | grep -E "'"$port"'"' done assuming the file with server-port pairs is called server and then extend that with your ssh command. The cat ...


2

You can do it with awk awk -F= '/^frame/{line=FILENAME "=" $2}NR!=1 && FNR==1{print line}END{print line}' *.txt Or with sed (GNU version more than 4.2.2) sed -sn '/^frame/{s///;h};${F;x;p}' *.txt | sed 'N;s/\n//'



Top 50 recent answers are included