Tag Info

New answers tagged

2

Line 4 of parent.sh, you wrote sh /child.sh & $f. The ampersand must be put at the end of the command like that: sh /child.sh $f &. In your case, you are trying to run sh /child.sh in background, and then you are executing $f in foreground, which will lead to a permission denied as I can assume that your files /vol4/commit/file[1-9] are not ...


2

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 ...


0

Count the lines: netstat -nat | egrep 'ESTABLISHED|TIME_WAIT|CLOSE_WAIT' | wc -l Print only those lines: netstat -nat | egrep 'ESTABLISHED|TIME_WAIT|CLOSE_WAIT'


3

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, ...


2

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.


2

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"


0

Even though you used the ksh tag in your question, the script starts with the #!/bin/sh hashbang, which will rarely give you a korn shell. The rest of the code works fine with ksh (AT&T ksh93) on ubuntu 14.04: $ ksh poc.sh 98.67 1.33 $ ls -lL /bin/ksh* -rwxr-xr-x 1 root root 1509040 Jan 9 2013 /bin/ksh -rwxr-xr-x 1 root root 1509040 Jan 9 2013 ...


6

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


5

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


1

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 ^ ^ ...



Top 50 recent answers are included