Tag Info

New answers tagged

0

These days I send to use sed for this type of thing. $ netstat -nt | sed -r -n 's/^tcp +[0-9]+ +[0-9]+ [0-9\.]+(:[0-9]+).+TIME_WAIT/\1/p' | sort | uniq -c | sort -n 5 :443 8 :80 Here we are interesting in a line that looks a specific way, but really one piece out of it. So we define the regex with a match group for that part and then print ...


0

I'm sure there's a cleaner way to do this without double-awk'ing and double-grep'ing. (Hopefully someone can expound upon this) Shell-based (ksh and bash) For-Loop for x in $ (netstat -nat | grep TIME_WAIT | awk '{print $4}' | \ awk -F":" '{print $2}' | sort -u) ; do printf "TIME_WAIT on Port $x : `netstat -nat|grep ":$x"|grep TIME_WAIT|wc ...


0

Just get rid of the continue command, it's not needed. Leave the ;;, though -- that's how the end of a case is indicated. The purpose of continue is to skip the remainder of a loop body, and start the next iteration. It has no meaning outside a loop, so you get this error. This isn't like C/Javascript/PHP -- you don't need a special statement at the end of ...


0

According to the man page for Signal (man 7 signal) a SIGBUS means Bus error (bad memory access). Since the problem is random or not easily reproduced 100% of the time, this means either; The Cron job is calling a program or script that is randomly failing A memory problem exists and should be checked for If it is the former (#1), then check the program ...


2

To fit with modern sysadmin best practices it would be good to add your configs as individual files in /etc/smb/smb.d and then reference them with an include. Sadly samba does not support wildcard includes so you have to do add something like: include = /etc/smb/includes.conf in your smb.conf and then generate the includes.conf with something like: ls ...


0

The "ASTERISK_PROMPT" is an environment variable and should be set prior to starting the CLI for it to take affect. i.e. export ASTERISK_PROMPT="%C31%H*CLI%#" asterisk -r As for your specific version, (Asterisk 11 branch) The reasons for not displaying colors is as follows: The command-line options to connect to the server includes the "no-color" flag. ...


5

Don't reinvent the wheel :) The Monit utility is purpose-built to handle this sort of situation. It's well-documented and has plenty of examples here on ServerFault. check system kale.GreenLeaf.com if loadavg (5min) > 16 for 15 cycles then alert if memory usage > 92% then alert if swap usage > 10% then alert or for a process: ...


2

What exactly are you trying to accomplish? You're probably trying to do it WRONG. [ $(free | perl -nE 'if (/Mem/) { (undef,$total,$used) = split; say int(100*$used/$total) }') -gt 80 ] && echo foo But note that whatever you are trying to accomplish with that is almost certainly useless (and probably even harmful). There is no such thing as ...


4

How about: [ $(free -m| grep Mem | awk '{ print int($3/$2*100) }') -gt "80" ] && echo "greater " || echo "lesser" And for the process consumption, here is a possible part of a solution: for p in $(pgrep bash); do total=$(($total + $(awk '/VmSize/ { print $2 }' /proc/$p/status))); done ; echo "Total memory usage: $total kb" ; unset total ...


0

list all users? pw usershow -a change multiple users to nogroup primary group? There's a hundred different ways to do this... I would: foreach u ("list" "of" "users") pw usermod -n $u -g NewPrimaryGroup end You could even get the list of users from a subcommand, like pw groupshow OldGroupName | sed -e "s/.*://" -e "s/,/\ /" ...


0

I think it may be that the file doesn't have permissions to run without bash (should be able to rectify by running "chmod +x" and your second command shouldn't include the "-c" switch to bash and the filename also doesn't need to be quoted.


1

Extending on Iain's script with a faster version for working with a large number of files. #!/bin/bash ftypes=$(find . -type f | grep -E ".*\.[a-zA-Z0-9]*$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort | uniq) for ft in $ftypes do echo -ne "$ft\t" find . -name "*${ft}" -exec du -bcsh '{}' + | tail -1 | sed 's/\stotal//' done


1

In essence this is the problem; directory from which you are doing the find is symlink; so relative move .. is not moving you to where you would expect; rather to .. of $(readlink -f $PWD) moo:~$ mkdir foo bar moo:~$ cd bar/ moo:~/bar$ ln -s ../foo/ moo:~/bar$ touch w00t moo:~/bar$ ls -1 foo w00t moo:~/bar$ cd foo moo:~/bar/foo$ ls -1 ../ bar foo cool ...



Top 50 recent answers are included