Category: shell
-
Requests per Second from Logfiles – Nginx, Apache
Requests per Second from Logfiles – Nginx, Apache http://stackoverflow.com/questions/4051555/how-do-i-get-the-number-of-requests-per-second-from-apache-log-between-2-dates-t while true; do tail -n0 -f /var/log/wowza/wowzamediaserver_access.log>/tmp/tmp.log & sleep 2; kill $! ; wc -l /tmp/tmp.log | cut -c-2; done 2>/dev/null As a bash function/alias rqs /var/log/access.log function requests_per_second(log_filepath){ # http://stackoverflow.com/questions/4051555/how-do-i-get-the-number-of-requests-per-second-from-apache-log-between-2-dates-t while true; do tail -n0 -f “${log_filepath}” > /tmp/tmp.log & sleep 2; kill $!; wc…
-
Unix – Permanent SSH Tunnel – The easy way 🙂
OK, this is a dead easy instruction of setting up a permanent ssh tunnel through cron This establishes port forwarding to a remote server. Command crontab -e nc -z localhost || ssh @ -N -L :: & Example * * * * * nc -z localhost 15432 || ssh a@big-bad-server.net -N -L 15432:10.0.80.1:5432 -L 25432:10.0.80.2:5432…
-
SED – Custom Separators – Dealing with Filepaths
a@t400:~$ echo “hello”| sed -e ‘s/e/ö/g’ höllo a@t400:~$ echo “hello”| sed -e ‘s#e#ö#g’ höllo a@t400:~$ echo “hello”| sed -e ‘s^e^ö^g’ höllo References http://backreference.org/2010/02/20/using-different-delimiters-in-sed/
-
Unix – Rename Files recursively using a for-loop and find command
find . -name “*.flv.mp4” | while read file; do echo “$file”; mv “$file” “${file%.flv.mp4}.mp4” #mv “$file” “$(expr “$file” : ‘\(.*\)\.flv.mp4’).mp4″ done; Notes: rename rename does not work: “$rename .html .txt *.html” results in… syntax error at (eval 1) line 1, near “.” basename basename does not work – only renames the filename and strip path!…
-
Unix – Count Requests Per Seconds From Access Log File
egrep “^14:59” access.log|grep exectime| sed ‘s/.*14:59.\(..\).*/\1/g’|sort |uniq -c|sort -n egrep “^14:” access.log|grep exectime| sed ‘s/.*14:\(…..\).*/\1/g’|sort |uniq -c|sort -n grep exectime access.log | awk ‘{print $1,$16,$7}’ > se1.log tail -f /var/logs/access.log|grep exectime | awk ‘{print $1,$16,$7}’ grep “job processed” res.log | awk ‘{ print $1″ “$2}’|sort -n|uniq -c|less Result: 6 2013-01-31 18:39:44 4 2013-01-31 18:39:45 34…
-
Unix – Extract multiple rar and zip files
Extract multiple zip files for z in *.zip; do unzip -f $z; done Extract multiple rar files for f in *.rar; do unrar -x $f; done unzip –help UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP. Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir] Default action is to extract files…
-
ffmpeg – Convert Adobe Flash FLV Files to MP4 Files
Simple Conversion of FLV to MP4 using FFMPEG ffmpeg chews the input buffers – use -nostdin flag to fix it find . -regextype posix-extended -iregex “.*.avi|.*.flv” -type f | while IFS= read -r file; do fn=”${file}”; echo “###$fn###”; dest=”${fn%.*}.mp4″; echo “###$dest###”; if [ -f “$dest” ];then rm “$dest”; fi; ffmpeg -nostdin -v 0 -i “$fn”…
-
Unix – grep, sort , uniq
Source File cat genre.txt ./014/735/54/00000000000001473554.xml ./014/735/10/00000000000001473510.xml ./014/726/18/00000000000001472618.xml ./014/726/26/00000000000001472626.xml ./014/726/08/00000000000001472608.xml ./014/726/42/00000000000001472642.xml grep Genre genre.txt |sed ‘s/.*Genre name=”\(.*\).>.*/\1/g’|sort|uniq –c grep Genre genre.txt |sed ‘s/.*Genre name=”\(.*\).>.*/\1/g’\ |sort|uniq -c|awk ‘{ print $2″\t”$1 }’|sort |sed ‘s/&apos//g’ grep Genre genre.txt |sed ‘s/.*Genre name=”\(.*\).>.*/\1/g’
-
Unix – Extract File Extension and Filename from Filepath
#file extension for f in *; do fn=”${f%.*}”;echo “fn=$fn,f=$f”; done;
-
Unix – tolower in bash, awk and sed
tr ‘[A-Z]’ ‘[a-z]’ # to lower case sed ‘s/]]/]/g’ # replace ]] with ] awk ‘{print tolower($0)}’ # change whole string to lower sed ‘s/^[0-9]*//g’ # replace all numbers with nothing