Tag Info

Hot answers tagged


Neither bash nor ksh can perform floating point arithmetic (ksh93 supports that if I remember correctly). I recommend to switch to zsh or run external tool like bc: $ CPU_IDLE=98.67 $ echo "$CPU_IDLE" $ CPU_USAGE=$( bc <<< "100 - $CPU_IDLE" ) $ echo "$CPU_USAGE" 1.33


With sort (it will also sort the output): sort -u file With awk (it doesn't sort, just filter out the duplicates, like the desired output): awk '!a[$0]++' file With perl (same principle as the awk one): perl -ne 'print unless $a{$_}++' file


Your script can be slightly modified to only process the states you need: netstat -ant | awk '/ESTABLISHED|LISTEN|CLOSE_WAIT/ {print $6}' | \ sort | uniq -c | sort -n A further step would be to everything with awk, e.g. : netstat -ant | awk ' /ESTABLISHED|LISTEN|CLOSE_WAIT/ {count[$6]++} END { for(s in count) { printf("%12s : %6d\n", s, ...


you have a typo on line 8 of your script, it should be: read dirname That's the reason you only get '5' printed, because $dirname is empty. What is happening is that when you do read $dirname the shell expands '$dirname' to it's value which is empty. Also on a side note, always use double-quotes when enclosing variables. Revised script: #!/bin/ksh echo ...


Nope - Running processes can't do that sort of thing, because they're backgrounded by the shell and its the shell's job to say which process is foregrounded / backgrounded / suspended. Try this - Remove the fg, and then run your shell script backgrounded (ie with a & on the end) When its finished, the output will be blurted to your console.


Add the --max-time option. You may also want to set --connect-timeout which will limit the amount of time that curl tries to connect to the server. Example: curl --output /dev/null --silent --head --fail --max-time 10 --connect-timeout 3 "$url"


I use these in mkshfor a user shell: # custom prompt see http://comments.gmane.org/gmane.os.miros.mksh/126 PS1=$'\a\r\a\e[1;34m\a ^ ^ ^ ^ | \a\e[36m\a${USER:=$(ulimit -c 0; id -un 2>/dev/null || echo \?)}@${HOSTNAME%%.*}\a\e[34m\a | ^ ^ ^ ^ | \a\e[0;33m\a$(local d=${PWD:-?} p=~; [[ $p = ?(*/) ]] || d=${d/#$p/~}; print -nr -- "$d")\a\e[1;34m\a |\n ^ ^ ...

Only top voted, non community-wiki answers of a minimum length are eligible