User Tools

Site Tools


shell2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
shell2 [2019/12/17 16:40] – search is hanging on shell page. This is a test page. dblumeshell2 [2024/10/07 22:00] (current) dblume
Line 51: Line 51:
 declare -r SCRIPT_NAME=$(basename "$BASH_SOURCE") declare -r SCRIPT_NAME=$(basename "$BASH_SOURCE")
  
-## exit the shell (default status code: 1) after printing the message to stderr+# exit (default status code: 1) after printing the message to stderr
 die() { die() {
     echo >&2 "$1"     echo >&2 "$1"
Line 274: Line 274:
     fi     fi
 } }
-</code> 
- 
-Note the use of $@ vs "$*" in the next function that automatically saves an archive of a telnet session. Also note that I remove spaces and colons. (Colons because they screw with opening files directly at line numbers). 
- 
-<code bash> 
-telnet_log() { 
-    curtime=$(date -Iseconds | tr : .) 
-    args=$(echo "$*" | tr ' ' '_') 
-    telnet $@ | tee $HOME/telnetlog/$args\_${curtime::-5}.log 
-} 
- 
-last_telnet_log() { 
-    ls -d1t $HOME/telnetlog/* | head -n 1 
-} 
-</code> 
- 
-Of course if you do that, you'll want to occasionally (via cronjob?) delete old archives. 
- 
-<code> 
-find $HOME/telnetlog/ -type f -mtime +6 -delete 
 </code> </code>
  
Line 312: Line 292:
 # at 3 in the morning on Mondays, delete files older than 30 days # at 3 in the morning on Mondays, delete files older than 30 days
 0 3 * * 1 find $HOME/.vim/backup/ -type f -mtime +30 -delete 0 3 * * 1 find $HOME/.vim/backup/ -type f -mtime +30 -delete
 +</code>
 +
 +====== Calculate web server bandwidth ======
 +
 +Use ''awk'' to add up a column from Apache logs:
 +
 +<code>
 +$ sudo cat /var/log/httpd/access_log | awk '{SUM+=$10}END{print SUM/1024/1024}'
 +0.855597
 </code> </code>
  
Line 390: Line 379:
 Alternatively, to see the RSS use of that process alone: Alternatively, to see the RSS use of that process alone:
 <code bash> <code bash>
-while true; do sync; cat /proc/$(pidof yourprocess)/status | grep VmRSS; sleep 1; done+PID=$(pidof yourprocess); while true; do sync; grep VmRSS /proc/$PID/status; sleep 1; done
 </code> </code>
 ====== Measuring Available Memory ====== ====== Measuring Available Memory ======
Line 554: Line 543:
 David's banana = 192.168.144.40 David's banana = 192.168.144.40
 </code> </code>
 +
 +====== XML XPath Tips ======
 +
 +Here's how to use xmllint to take an XPath path to extract info from the Roku ECP Apps list.
 +
 +  http 192.168.1.128:8060/query/apps | xmllint --xpath '//app[text()="dxb"]/@id' - | cut -d\" -f 2
 +  http 192.168.1.128:8060/query/apps | xmllint --xpath '//app[contains(text(), "Netflix")]/@id' - | cut -d\" -f 2
 +
  
 ====== Protips for find ====== ====== Protips for find ======
Line 563: Line 560:
   find lib -type f -name \*.so\* -exec sh -c 'objdump -p "$1" | grep "NEEDED.*libz"' - {} \; -print   find lib -type f -name \*.so\* -exec sh -c 'objdump -p "$1" | grep "NEEDED.*libz"' - {} \; -print
      
-Note that you can pass -print (or -and -print) after a -exec argument. Also, the " - " is just a placeholder for $0 (usually the command name, in this case "sh"), we want $1 to be {}. It outputs results like:+Note that you can pass -print (or -and -print) after a -exec argument. You can also use -printf, ex., ''-printf %%"%%\t%f\n%%"%%''. Also, the " - " is just a placeholder for $0 (usually the command name, in this case "sh"), we want $1 to be {}. It outputs results like:
  
     NEEDED               libz.so.1     NEEDED               libz.so.1
   lib/libprotoc.so.13.0.2   lib/libprotoc.so.13.0.2
  
 +Tip: tar up the last day's worth of log files:
 +
 +  find . -mtime -1 -name \*.log -print0 | tar -jcvf logs.tar.bz2 --null -T -
 ====== Additional Keywords ====== ====== Additional Keywords ======
  
 Linux, Unix, *nix Linux, Unix, *nix
shell2.1576629652.txt.gz · Last modified: 2023/04/12 20:44 (external edit)