this decouples us from the USER variable, which cron doesn't provide to us anyway.
# cron default bits to add at top of crontab...
# by fred t. hamster, GNU GPL v3 license.
-# these stanzas are assumed to be present in every one of the other cron
-# example files. unfortunately there is no way to include cron files in other
-# cron files, so the functional parts here should just be pasted directly into
-# the user's crontab.
+# every one of the crontab examples in feisty meow depends on the the stanzas
+# below. (unfortunately there is no way to include cron files in other cron
+# files, so the functional parts here should just be pasted directly into the
+# user's crontab at the top.)
+
+# set a user name for writing unique log files. this is important because
+# cron doesn't have the normal variable 'USER' defined. cron does define
+# HOME, which is pretty lucky for us...
+# please change the name to the user running the cronjob, or to whatever
+# unique string you'd like to use:
+CRONUSER=fred
# set the shell to bash. (not the default for some cron implementations.)
SHELL=/bin/bash
# the wildcard form of a crontab line is this: "* * * * * command"
# that "command" will execute every single minute.
-# set a user name for writing unique log files. this is important because
-# cron doesn't have the variable USER defined. cron does define HOME, which
-# is pretty lucky for us...
-# you may want to use a more appropriate user name than mine, which is "fred".
-USER=fred
-
# the guts of the crontab would follow below. this usually is a set of valid
# crontab lines that spell the time or times for commands to be executed. my
# crontabs usually have from 3 to 8 entries because i tend to atomicize the
# with cron job output on some systems. you can use the normal output
# redirection operators to do this (e.g. '>', '2>', '&>', '>>' and '&>>').
# /dev/null works as an output target if you don't ever want to see the
-# results from your cron jobs. i usually prefer to write log files in the /tmp
-# directory with the ${USER} variable in the file name. here's an example of
-# a real command with output that will *append* both output and error streams
-# ('&>>') to an output file. if your output can be huge, then you may want to
-# overwrite the output file instead ('&>').
+# results from your cron jobs. i usually prefer to write log files in the
+# /tmp directory with the ${CRONUSER} variable added in the file name.
+# below is a live example which we almost always include, so it's embedded
+# here for convenience.
#[nechung fortune]
# runs every minute and recreates a fortune for thunderbird signature.
# a lot of the detail below is to get the feisty meow environment loaded for
# the new_sig command.
-* * * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; perl $HOME/feisty_meow/scripts/text/new_sig.pl) &>>/tmp/${USER}-cron-nechung_fortune.log
+* * * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; perl $HOME/feisty_meow/scripts/text/new_sig.pl) &>>/tmp/${CRONUSER}-cron-nechung_fortune.log
#[backup git account]
# archives the whole ~git folder with all account databases into a compressed tar file.
-34 20 * * 5 tar -czf /z/stuffing/archives/git_archive_$(date +"\%Y_\%m_\%d_\%H\%M_\%S" | tr -d '/\n/').tar.gz /home/git &>>/tmp/${USER}-cron-backup_git_account.log
+34 20 * * 5 tar -czf /z/stuffing/archives/git_archive_$(date +"\%Y_\%m_\%d_\%H\%M_\%S" | tr -d '/\n/').tar.gz /home/git &>>/tmp/${CRONUSER}-cron-backup_git_account.log
#[backup maildir]
# backs up the maildir folder for fred bi-monthly.
-8 4 3,14 * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; tar -czf /z/stuffing/archives/maildir_backup_$(date_stringer).tar.gz $HOME/Maildir) &>/tmp/${USER}-cron-backup_maildir.log
+8 4 3,14 * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; tar -czf /z/stuffing/archives/maildir_backup_$(date_stringer).tar.gz $HOME/Maildir) &>/tmp/${CRONUSER}-cron-backup_maildir.log
#[backup mysql databases]
# backs up all of our mysql databases on a weekly basis.
-28 4 * * 2 (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; mysqldump -u root '-pPASSWORD' --all-databases | gzip > /z/stuffing/archives/database_backup_$(hostname)_$(date_stringer).sql.gz) &>>/tmp/${USER}-cron-backup_mysql_databases.log
+28 4 * * 2 (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; mysqldump -u root '-pPASSWORD' --all-databases | gzip > /z/stuffing/archives/database_backup_$(hostname)_$(date_stringer).sql.gz) &>>/tmp/${CRONUSER}-cron-backup_mysql_databases.log
#[backup photo albums]
# back up the pictures in coppermine gallery every month.
-34 6 4 * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; tar -czf /z/stuffing/archives/photo_albums_backup_$(date_stringer).tar.gz /home/albums ; refred) &>>/tmp/${USER}-cron-backup_photo_albums.log
+34 6 4 * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; tar -czf /z/stuffing/archives/photo_albums_backup_$(date_stringer).tar.gz /home/albums ; refred) &>>/tmp/${CRONUSER}-cron-backup_photo_albums.log
#[backup serene system]
# backs up config files and important parts of home directories to off-machine storage.
-14 2 * * */7 (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; bash $HOME/feisty_meow/scripts/archival/serene_backer_upper.sh) &>>/tmp/${USER}-cron-backup_serene_system.log
+14 2 * * */7 (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; bash $HOME/feisty_meow/scripts/archival/serene_backer_upper.sh) &>>/tmp/${CRONUSER}-cron-backup_serene_system.log
#[backup trac]
# backs up trac every week.
-28 7 * * 2 bash $HOME/feisty_meow/scripts/archival/backup_trac.sh /home/trac /z/stuffing/archives &>>/tmp/${USER}-cron-backup_trac.log
+28 7 * * 2 bash $HOME/feisty_meow/scripts/archival/backup_trac.sh /home/trac /z/stuffing/archives &>>/tmp/${CRONUSER}-cron-backup_trac.log
#[bookmarks builder]
# regenerate the bookmarks pages.
-24 10 * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; bash $HOME/feisty_meow/scripts/bookmarks/create_marks.sh ) &>>/tmp/${USER}-cron-bookmarks_builder.log
+24 10 * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; bash $HOME/feisty_meow/scripts/bookmarks/create_marks.sh ) &>>/tmp/${CRONUSER}-cron-bookmarks_builder.log
#[chkrootkit]
# this runs chkrootkit to demonstrate a bug in the vm kernel currently
# provided by...? hmmm: who's the vendor?
-3 * * * * (/usr/sbin/chkrootkit -q &>/var/www/rootkit_report_quiet.txt ) &>>/tmp/${USER}-cron-chkrootkit.log
-4 * * * * (/usr/sbin/chkrootkit -x &>/var/www/rootkit_report_expert.txt ) &>>/tmp/${USER}-cron-chkrootkit.log
+3 * * * * (/usr/sbin/chkrootkit -q &>/var/www/rootkit_report_quiet.txt ) &>>/tmp/${CRONUSER}-cron-chkrootkit.log
+4 * * * * (/usr/sbin/chkrootkit -x &>/var/www/rootkit_report_expert.txt ) &>>/tmp/${CRONUSER}-cron-chkrootkit.log
#[doxygen]
# update the feisty meow documentation once on each of tuesday, thursday and saturday.
-20 4 * * 2,4,6 (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; cd $HOME/feisty_meow/documentation; make) &>>/tmp/${USER}-cron-doxygen.log
+20 4 * * 2,4,6 (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; cd $HOME/feisty_meow/documentation; make) &>>/tmp/${CRONUSER}-cron-doxygen.log
#[emit crontab]
# meta-operation to backup the crontab file using cron itself.
-28 */8 * * * crontab -l >$HOME/$(hostname).$USER.crontab
+28 */8 * * * crontab -l >$HOME/$(hostname).$CRONUSER.crontab
#[letsencrypt renewal]
# run the letsencrypt certificate renewal process every 4 hours.
-37 */4 * * * letsencrypt renew &>>/tmp/${USER}-cron-letsencrypt_renewal.log
+37 */4 * * * letsencrypt renew &>>/tmp/${CRONUSER}-cron-letsencrypt_renewal.log
# runs every minute and recreates a fortune for thunderbird signature.
# a lot of the detail below is to get the feisty meow environment loaded for
# the new_sig command.
-* * * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; perl $HOME/feisty_meow/scripts/text/new_sig.pl) &>>/tmp/${USER}-cron-nechung_fortune.log
+* * * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; perl $HOME/feisty_meow/scripts/text/new_sig.pl) &>>/tmp/${CRONUSER}-cron-nechung_fortune.log
#[opensim restart]
# ensure opensim is started if we can't detect it as running.
-*/5 * * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; bash $HOME/feisty_meow/scripts/opensim/maybe_restart_opensim.sh) &>>/tmp/${USER}-cron-opensim_restart.log
+*/5 * * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; bash $HOME/feisty_meow/scripts/opensim/maybe_restart_opensim.sh) &>>/tmp/${CRONUSER}-cron-opensim_restart.log
#[pack feisty for web]
# this packs up our source code distributions every 8 days.
-16 22 */8 * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; bash $HOME/feisty_meow/scripts/archival/pack_feisty_meow.sh) &>>/tmp/${USER}-cron-pack_feisty_for_web.log
+16 22 */8 * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; bash $HOME/feisty_meow/scripts/archival/pack_feisty_meow.sh) &>>/tmp/${CRONUSER}-cron-pack_feisty_for_web.log
#[process check]
# a crontab for periodically dumping the process state.
-* * * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; bash $HOME/feisty_meow/scripts/processes/show_hot_ones.sh) &>>/tmp/${USER}-cron-active_processes.log
+* * * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; bash $HOME/feisty_meow/scripts/processes/show_hot_ones.sh) &>>/tmp/${CRONUSER}-cron-active_processes.log
#[random sound]
-* * * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; bash $HOME/feisty_meow/scripts/multimedia/randomly_play.sh) &>>/tmp/${USER}-cron-random_sound.log
+* * * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; bash $HOME/feisty_meow/scripts/multimedia/randomly_play.sh) &>>/tmp/${CRONUSER}-cron-random_sound.log
#[snarf linux configuration]
# do a backup of the linux configuration files once a week.
-28 7 * * 4 (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; cd /z/stuffing/archives; perl $HOME/feisty_meow/scripts/archival/snarf_linux_config.pl) &>>/tmp/${USER}-cron-snarf_linux_configuration.log
+28 7 * * 4 (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; cd /z/stuffing/archives; perl $HOME/feisty_meow/scripts/archival/snarf_linux_config.pl) &>>/tmp/${CRONUSER}-cron-snarf_linux_configuration.log
# repositories, such as sourceforge or github. the uploading process (which we think of as sending
# those updated items swimming downstream to their dependent repositories) is done automatically in
# our makefiles. that's why the code below relies on the top-level makefile in home.
-14 3 * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; cd $HOME ; rev_update ; make ) &>>/tmp/${USER}-cron-synch_and_swim_downstream.log
+14 3 * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; cd $HOME ; rev_update ; make ) &>>/tmp/${CRONUSER}-cron-synch_and_swim_downstream.log
#[tell zooty our ip]
# firewall host only--inform serene/zooty of our home IP address to enable back-connections.
-0,14,28,42,56 * * * * (bash /home/fred/feisty_meow/scripts/security/tell_zooty_our_ip.sh serene.feistymeow.org fred fred ) &>>/tmp/${USER}-cron-tell_zooty_our_ip.log
+0,14,28,42,56 * * * * (bash /home/fred/feisty_meow/scripts/security/tell_zooty_our_ip.sh serene.feistymeow.org fred fred ) &>>/tmp/${CRONUSER}-cron-tell_zooty_our_ip.log
#[time synch]
# standard to synch to local machine.
-#0,4,8,12,16,20,24,28,32,36,40,44,48,52,56 * * * * /usr/sbin/sntp -P no -r greendragon &>>/tmp/${USER}-cron-time_synch.log
+#0,4,8,12,16,20,24,28,32,36,40,44,48,52,56 * * * * /usr/sbin/sntp -P no -r greendragon &>>/tmp/${CRONUSER}-cron-time_synch.log
#or
-0,4,8,12,16,20,24,28,32,36,40,44,48,52,56 * * * * /usr/bin/rdate -s -n greendragon &>>/tmp/${USER}-cron-time_synch.log
+0,4,8,12,16,20,24,28,32,36,40,44,48,52,56 * * * * /usr/bin/rdate -s -n greendragon &>>/tmp/${CRONUSER}-cron-time_synch.log
# -n is nntp which may not work with govt servers.
# one machine on the network uses this version, to synch externally.
-#0 0,4,8,12,16,20 * * * /usr/sbin/sntp -P no -r time.nist.gov &>>/tmp/${USER}-cron-time_synch.log
+#0 0,4,8,12,16,20 * * * /usr/sbin/sntp -P no -r time.nist.gov &>>/tmp/${CRONUSER}-cron-time_synch.log
#or
-0 0,4,8,12,16,20 * * * /usr/bin/rdate -s time-c.nist.gov &>>/tmp/${USER}-cron-time_synch.log
+0 0,4,8,12,16,20 * * * /usr/bin/rdate -s time-c.nist.gov &>>/tmp/${CRONUSER}-cron-time_synch.log
#[uptime report]
# the script writes the current time and current uptime to the log file.
-0 * * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; bash $HOME/feisty_meow/scripts/system/write_uptime_report.sh) &>>/tmp/${USER}-cron-uptime_report.log
+0 * * * * (source $HOME/feisty_meow/scripts/core/launch_feisty_meow.sh; bash $HOME/feisty_meow/scripts/system/write_uptime_report.sh) &>>/tmp/${CRONUSER}-cron-uptime_report.log
full liberation.
-- Gampopa, from "The Jewel Ornament of Liberation", published by Shambhala
Publications
+~
+i try to think of 10,008 impossible things before breakfast,
+and i'm near ecstatic if any of those is worth writing down.
+ -- fred t. hamster
#!/bin/bash
+# counts the number of files in a set of directories.
+# if no directories are provided, uses the current working directory.
-# make sure they gave us some arguments.
-if [ -z "$1" ]; then
+# make sure they gave us some arguments, or go with our default of the current dir.
#hmmm: could use the count notation instead of sloppy empty check.
- # reset first arg to be '*' to do any directories here.
-#echo changing args to use all subdirs in current dir.
+if [ -z "$1" ]; then
+ # reset the arguments list to scan any directories found in cwd.
+ SAVEIFS="$IFS"
+ IFS=$(echo -en "\n\b")
set -- $(find . -maxdepth 1 -mindepth 1 -type d) "${@:2}"
-#echo "arg 1 is now '$1'"
+ IFS="$SAVEIFS"
fi
-# run through all the parameters provided and find any
-# directories under them (or probably barf if they're not
-# dirs).
-for i in "${@}" ; do
+# run through all the parameters provided and find any directories under them
+# (or probably barf if they're not dirs).
+#hmmm: really? "barf" is an implementation strategy now?
+for countfilesname in "${@}" ; do
+# echo "arg is: '$countfilesname'"
# print the count of files followed by directory name,
# with leading zeros to allow sorting, which get
# redigested as spaces before showing the list.
- printf "%06d -- %s\n" $(find "$i" -type f | wc -l) "$i"
+ printf "%06d -- %s\n" $(find "$countfilesname" -type f | wc -l) "$countfilesname"
done |
# provide sorted output based on how many files exist
# in each directory.