Commands tagged logging (15)

  • This command will log the output of your simple cronjobs to syslog, and syslog will take it from there. Works great for monitoring scripts which only produce simple output. Advantages: * This can be used by regular users, without modifying system files like /etc/syslog.conf * Reduce cron spam to root@localhost (Please stop spaming the sysadmins) * Uses common tools like syslog (and logrotate) so that you don't need to maintain yet another krufty logfile. * Still ensures that the output is logged somewhere, for posterity. Perhaps it's stored the secure, central syslog server, for example. * Seems to work fine on Ubuntu, CentOS, FreeBSD & MacOSX Show Sample Output


    6
    */5 * * * * root /usr/local/nagios/sbin/nsca_check_disk 2>&1 |/usr/bin/logger -t nsca_check_disk
    StefanLasiewski · 2010-07-02 00:47:05 6
  • When debugging an ssh connection either to optimize your settings ie compression, ciphers, or more commonly for debugging an issue connecting, this alias comes in real handy as it's not easy to remember the '-o LogLevel=DEBUG3' argument, which adds a boost of debugging info not available with -vvv alone. Especially useful are the FD info, and the setup negotiation to create a cleaner, faster connection. Show Sample Output


    4
    alias sshv='ssh -vvv -o LogLevel=DEBUG3'
    AskApache · 2010-10-30 11:23:52 4
  • This will show all changes in all log files under /var/log/ that are regular files and don't end with `gz` nor with a number Show Sample Output


    4
    find /var/log -type f -iregex '.*[^\.][^0-9]+$' -not -iregex '.*gz$' 2> /dev/null | xargs tail -n0 -f | ccze -A
    rubo77 · 2014-07-29 17:11:17 5

  • 3
    tail -f file |xargs -IX printf "$(date -u)\t%s\n" X
    unefunge · 2010-11-25 11:23:13 5
  • A wrapper around ssh to automatically provide logging and session handling. This function runs ssh, which runs screen, which runs script. . The logs and the screen session are stored on the server. This means you can leave a session running and re-attach to it later, or from another machine. . . Requirements: * Log sessions on a remote server * Transparent - nothing extra to type * No installation - nothing to copy to the server beforehand . Features: * Function wrapper delegating to ssh - so nothing to remember - uses .ssh/config as expected - passes your command line option to ssh * Self-contained: no scripts to install on the server * Uses screen(1), so is: - detachable - re-attachable - shareable * Records session using script(1) * Configurable log file location, which may contain variables or whitespace L="$HOME" # local variable L="\$HOME" # server variable L="some space" . Limitations: * Log dir/file may not contain '~' (which would require eval on the server) . . The sessions are named by the local user connecting to the server. Therefore if you detach and re-run the same command you will reconnect to your original session. If you want to connect/share another's session simply run: USER=bob ssh root@server . The command above is stripped down to an absolute minimum. A fully expanded and annotated version is available as a Gist (git pastebin): https://gist.github.com/flatcap/3c42326abeb1197ee714 . If you want to add timing info to script, change the command to: ssh(){ L="\$HOME/logs/$(date +%F_%H:%M)-$USER";/usr/bin/ssh -t "$@" "mkdir -p \"${L%/*}\";screen -xRRS $USER script --timing=\"$L-timing\" -f \"$L\"";} Show Sample Output


    3
    ssh(){ L="\$HOME/logs/$(date +%F_%H:%M)-$USER";/usr/bin/ssh -t "$@" "mkdir -p \"${L%/*}\";screen -xRRS $USER script -f \"$L\"";}
    flatcap · 2015-10-14 13:14:29 11

  • 1
    pygmentize -l pytb myapp.log | less -SR
    manuq · 2013-01-10 03:13:41 4
  • You could also pipe to logger.


    1
    logger -t MyProgramName "Whatever you're logging"
    pdxdoughnut · 2013-10-22 16:34:49 6
  • This is similar to standard `pv`, but it retains the rate history instead of only showing the current rate. This is useful for spotting changes. To do this, -f is used to force pv to output, and stderr is redirected to stdout so that `tr` can swap the carriage returns for new lines. (doesn't work correctly is in zsh for some reason. Tail's output isn't redirected to /dev/null like it is in bash. anyone know why? ???????) Show Sample Output


    1
    tail -f access.log | pv -l -i10 -r -f 2>&1 >/dev/null | tr /\\r \ \\n
    varenc · 2020-04-19 02:07:40 95
  • GoAccess is an open source real-time Apache web log analyzer and interactive viewer that runs in a terminal in *nix systems. It provides fast and valuable HTTP statistics for system administrators that require a visual server report on the fly. http://goaccess.prosoftcorp.com/ Show Sample Output


    0
    sed -n '/05\/Dec\/2010/,$ p' access.log | goaccess -s -b
    allinurl · 2010-12-13 17:37:33 3
  • Put this logging function in you're script, when need it call it. command || logme "Error with command"


    0
    logme(){ echo "$(date +%d-%m-%Y-%H:%M) => $0 @ $1 returned error" >> persoscript.log }
    qcjn · 2013-10-22 15:55:01 6
  • This bash one-liner will let you watch the tail end of a log file in real time.


    0
    watch -n 4 "tail -n $(expr $(tput lines) - 4) /var/log/apache2/access.log | cut -c 1-$(tput cols)"
    atw527 · 2013-12-03 23:45:25 9
  • IMPORTANT: You need Windows PowerShell to run this command - in your Windows Command Prompt, type powershell Uses sajb to start a PowerShell background job that pings an IP host every 10 seconds. Any changes in the host's Up/Down state is time-stamped and logged to a file. Date/time stamps are logged in two formats: Unix and human-readable. A while(1) loop repeats the test every 10 seconds by using the sleep command. See the Sample Output for more detail. I use this command to log Up/Down events of my Motorola SB6141 cable modem (192.168.100.1). To end the logging, close the PowerShell window or use the "exit" command. Show Sample Output


    0
    sajb {$ip="192.168.100.1";$old=0;while(1){$up=test-connection -quiet -count 1 $ip;if($up-ne$old){$s=(date -u %s).split('.')[0]+' '+(date -f s).replace('T',' ')+' '+$ip+' '+$(if($up){'Up'}else{'Down'});echo $s|out-file -a $home\ping.txt;$old=$up}sleep 10}}
    omap7777 · 2015-12-28 20:33:08 15
  • Run a job in the background and prefix it's output with some string. This is particularly useful if you are running inside a docker container in a startup script (sue me, I'll run two jobs in a docker container if I want to) and you can run something like: /usr/sbin/nginx 2>&1 | awk '{print "[NGINX] " $0}' & /opt/jws-3.1/tomcat8/bin/catalina.sh run 2>&1 | awk '{print "[TOMCAT] " $0}' & while true; do ; done it can also be combined with tee to create a file log as well as a stdout log, for example if the script above where a script called "/bin/start-container.sh" then you could run /bin/start-container.sh | tee /var/log/containerlogs Show Sample Output


    0
    nginx 2>&1 | awk '{print "[NGINX] " $0}' &
    hvindin · 2017-04-25 22:18:38 20
  • Tail all logs that are opened by all java processes. This is helpful when you are on a new environment and you do not know where the logs are located. Instead of java you can put any process name. This command does work only for Linux. The list of all log files opened by java process: sudo ls -l $(eval echo "/proc/{$(echo $(pgrep java)|sed 's/ /,/')}/fd/")|grep log|sed 's/[^/]* //g'


    -1
    sudo ls -l $(eval echo "/proc/{$(echo $(pgrep java)|sed 's/ /,/')}/fd/")|grep log|sed 's/[^/]* //g'|xargs -r tail -f
    vutcovici · 2010-07-30 18:20:00 3

  • -4
    while sleep 1; do date; (netstat -a -n | grep 80) ; done
    hute37 · 2011-05-16 07:56:56 5

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Colorized grep in less
Get your colorized grep output in less(1). This involves two things: forcing grep to output colors even though it's not going to a terminal and telling less to handle those properly.

Replace space in filename
This commands removes space from all the files with specific extension. I've specifed *.jpg as an example.

a function to find the fastest DNS server
http://public-dns.info gives a list of online dns servers. you need to change the country in url (br in this url) with your country code. this command need some time to ping all IP in list.

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Indent a one-liner.
Bash builtin type also indents the function.

Indicates the position of my monitor buttons
I often need to change the brightness of my monitor. The symbols of the sensor buttons are not illuminated and on a black background .... invisible! Now i use osd_cat instead of a torch ;-)

Export a directory to all clients via NFSv4, read/write.
This exports a directory to the world in read/write mode. It is useful for quick, temporary NFS exports. Consider restricting the clients to a subnet or to specific hosts for security reasons (the client can be specified before the colon). On the client: mount -t nfs4 hostname:/ /mountpoint To terminate all of the exports (after unmounting on the client): exportfs -u -a Leave out the fsid=0 option if you don't want NFSv4. This works under recent versions of Linux.

Adding Prefix to File name
Adding course name prefix to lecture pdfs

Hide the name of a process listed in the `ps` output
$ exec -a $NAME $COMMAND $ARGS `your_cmd -erase_all_files` is the real process, but harmless-looking getty appears in the process table. Never actually had a need to do this, but interesting nonetheless... Tested in bash, dash. $ -a $NAME "pass NAME as the zeroth argument to COMMAND", i.e. customise the name of the process (as commonly seen with `ps`)

Install Linux Kernel Headers


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: