msgbartop
A chronological documentation test project, nothing serious, really!
msgbarbottom

09 Jun 2007 Synchronize current directory with remote one using rsync

This is a simple way to synchronize all the files from the current computer to a remote computer using SSH as transportation protocol.

rsync -raz --progress --delete --bwlimit=4096 /synchronize/from/this-folder/ remote-server:/to/this-folder/

This example is using PUT as transfer method because the files are put from the local computer to the remote.

Options explained

  • -r synchronize directories recursive
  • a archive, preserves file attributes, ownership, timestamps…
  • z compress data, saves bandwidth but is CPU intensive
  • –progress shows the progress of all the files that are being syncronized
  • –delete delete files remotely that no longer exist locally
  • –bwlimit=4096 specify a maximum transfer rate of 4096 kilobytes per second.

Tags: ,

Posted by

09 Jun 2007 Backup harddisk to remote machine

dd bs=1M if=/dev/hda | gzip | ssh user@remote 'dd of=hda.gz'

Tags: , , ,

Posted by

09 Jun 2007 Set file timestamp (YYMMDDhhmm)

touch -c -t 0304050607 file

Tags:

Posted by

07 Jun 2007 Replace word in files

Example: replace Strict with Transitional in your PHP-files

sed -i -e 's/Strict/Transitional/' *.php

Warning!
Edit files in place

Tags:

Posted by

04 Jun 2007 How do I save or redirect stdout and stderr into different files?

Q. I need to run a program called oraMon.pl. However this program is run from cron job. It report error to stderr and normal output to stdout. How do I save stdout, stderr and both into 3 separate log files?

A. It is not that hard if you know howto redirect stderr, stdout and a small command called tee.

=> fd0 is stdin
=> fd1 is stdout
=> fd2 is stderr

There are two formats for redirecting standard output and standard error:
&>word
and
>&word

For example anything written to fd2 to the same place as output to fd1, you will use:
2>&1

tee command read from standard input and write to standard output and file.

So to send stderr to /tmp/errors.log, stdout to /tmp/output.log and both to /tmp/final.log, type as follows:

((/path/to/oraMon.pl 2>&1 1>&3 | tee /tmp/errors.log) 3>&1 1>&2 | tee /tmp/output.log) > /tmp/final.log 2>&1

Read bash man page and tee command for more information.

Tags: , ,

Posted by