Companionway

Meeting challenges with success

How to print the remainder of a line using awk

... eliminate the first X columns ...

#How to print remainder of line using awk

eliminate the first X columns…

Here is your challenge you have a list of cronjobs and you want to just execute the scheduled backup command with its arguments for a test run.

Using one command line, how would you do it?

Here is a sample root cronjob and I want to run the first entry with its arguments as a test run:

# m h  dom mon dow   command
 0 16  *   *   * /data/share/home/geoffm/dev/utils/bak-it.sh -i /usr/local/etc/include.lst -e /usr/local/etc/exclude.lst -t /data/bak/`hostname` -s 7 >/dev/null 2>&1
  5 0  *   *   * /data/share/motion/arch-files.sh >/dev/null 2>&1
*/15 *  *   *   * /data/share/home/geoffm/grab-pic.sh >/dev/null 2>&1
####### below are WIP or OLD ########
# 16 6  *   *   * /usr/sbin/lynis -c --auditor "automated" --cronjob --quiet >/dev/null 2>&1
#*/5 *  *   *   * /usr/local/bin/watch-proc.sh -f /usr/local/etc/watch-proc.conf -n geoffm@localhost >/dev/null 2>&1
#*/5 * * * * /data/share/home/geoffm/ping-pong.sh "ping -c2 192.168.1.55" "ssh 192.168.1.1 reboot" >/dev/null
#  7 * * * /usr/local/sbin/postfix_report.sh &> /dev/null

Centering a string

using awk...

Center a string using awk

awk = everyone’s favorite - right?

People who know me also know that I prefer simple universally available tools to get a job done. Awk is probably one of my favorites because it does pretty much anything I need for quick and simple jobs. It is far more powerful than most people realize including associative arrays and it will do anything grep and sed
can do.

Recently I had the need to center a string of text. This is a easy problem that pretty much any freshman programmer can accomplish in a heartbeat but I decided to do it with awk. This sample gives you a chance to explore rudimentary features of awk.