From 4cfdd08aaad4926a3133d96076d3e4cae78adb3a Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Mon, 6 Feb 2017 19:00:23 -0500 Subject: [PATCH] updated to specific CRONUSER variable this decouples us from the USER variable, which cron doesn't provide to us anyway. --- .../cron/aa_cron_defaults.crontab | 32 +++++++++---------- .../cron/backup_git_account.crontab | 2 +- .../configuration/cron/backup_maildir.crontab | 2 +- .../cron/backup_mysql_databases.crontab | 2 +- .../cron/backup_photo_albums.crontab | 2 +- .../cron/backup_serene_system.crontab | 2 +- .../configuration/cron/backup_trac.crontab | 2 +- .../cron/bookmarks_builder.crontab | 2 +- .../configuration/cron/chkrootkit.crontab | 4 +-- infobase/configuration/cron/doxygen.crontab | 2 +- .../configuration/cron/emit_crontab.crontab | 2 +- .../cron/letsencrypt_renewal.crontab | 2 +- .../cron/nechung_fortune.crontab | 2 +- .../cron/opensim_restart.crontab | 2 +- .../cron/pack_feisty_for_web.crontab | 2 +- .../configuration/cron/process_check.crontab | 2 +- .../configuration/cron/random_sound.crontab | 2 +- .../cron/snarf_linux_configuration.crontab | 2 +- .../cron/synch_and_swim_downstream.crontab | 2 +- .../cron/tell_zooty_our_ip.crontab | 2 +- .../configuration/cron/time_synch.crontab | 8 ++--- .../configuration/cron/uptime_report.crontab | 2 +- infobase/fortunes.dat | 4 +++ scripts/files/count_files.sh | 24 ++++++++------ 24 files changed, 59 insertions(+), 51 deletions(-) diff --git a/infobase/configuration/cron/aa_cron_defaults.crontab b/infobase/configuration/cron/aa_cron_defaults.crontab index 41015fdc..a91c88bc 100644 --- a/infobase/configuration/cron/aa_cron_defaults.crontab +++ b/infobase/configuration/cron/aa_cron_defaults.crontab @@ -4,10 +4,17 @@ # 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 @@ -30,12 +37,6 @@ 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 @@ -51,16 +52,15 @@ USER=fred # 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 diff --git a/infobase/configuration/cron/backup_git_account.crontab b/infobase/configuration/cron/backup_git_account.crontab index ab75d0bc..a08e239a 100644 --- a/infobase/configuration/cron/backup_git_account.crontab +++ b/infobase/configuration/cron/backup_git_account.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/configuration/cron/backup_maildir.crontab b/infobase/configuration/cron/backup_maildir.crontab index c3fa624b..752f6e02 100644 --- a/infobase/configuration/cron/backup_maildir.crontab +++ b/infobase/configuration/cron/backup_maildir.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/configuration/cron/backup_mysql_databases.crontab b/infobase/configuration/cron/backup_mysql_databases.crontab index 4bca961e..991b6f6f 100644 --- a/infobase/configuration/cron/backup_mysql_databases.crontab +++ b/infobase/configuration/cron/backup_mysql_databases.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/configuration/cron/backup_photo_albums.crontab b/infobase/configuration/cron/backup_photo_albums.crontab index 32a52004..a061dd94 100644 --- a/infobase/configuration/cron/backup_photo_albums.crontab +++ b/infobase/configuration/cron/backup_photo_albums.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/configuration/cron/backup_serene_system.crontab b/infobase/configuration/cron/backup_serene_system.crontab index 146a16d4..cfbff040 100644 --- a/infobase/configuration/cron/backup_serene_system.crontab +++ b/infobase/configuration/cron/backup_serene_system.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/configuration/cron/backup_trac.crontab b/infobase/configuration/cron/backup_trac.crontab index 992446a8..007cb024 100644 --- a/infobase/configuration/cron/backup_trac.crontab +++ b/infobase/configuration/cron/backup_trac.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/configuration/cron/bookmarks_builder.crontab b/infobase/configuration/cron/bookmarks_builder.crontab index acd7cc04..0c6f888b 100644 --- a/infobase/configuration/cron/bookmarks_builder.crontab +++ b/infobase/configuration/cron/bookmarks_builder.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/configuration/cron/chkrootkit.crontab b/infobase/configuration/cron/chkrootkit.crontab index 778a2648..1087ce00 100644 --- a/infobase/configuration/cron/chkrootkit.crontab +++ b/infobase/configuration/cron/chkrootkit.crontab @@ -2,6 +2,6 @@ #[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 diff --git a/infobase/configuration/cron/doxygen.crontab b/infobase/configuration/cron/doxygen.crontab index fa51d99a..c75baed6 100644 --- a/infobase/configuration/cron/doxygen.crontab +++ b/infobase/configuration/cron/doxygen.crontab @@ -1,6 +1,6 @@ #[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 diff --git a/infobase/configuration/cron/emit_crontab.crontab b/infobase/configuration/cron/emit_crontab.crontab index 627d16dc..152dd4b0 100644 --- a/infobase/configuration/cron/emit_crontab.crontab +++ b/infobase/configuration/cron/emit_crontab.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/configuration/cron/letsencrypt_renewal.crontab b/infobase/configuration/cron/letsencrypt_renewal.crontab index 18a43ef6..4a343de0 100644 --- a/infobase/configuration/cron/letsencrypt_renewal.crontab +++ b/infobase/configuration/cron/letsencrypt_renewal.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/configuration/cron/nechung_fortune.crontab b/infobase/configuration/cron/nechung_fortune.crontab index b220c2de..c8c6375c 100644 --- a/infobase/configuration/cron/nechung_fortune.crontab +++ b/infobase/configuration/cron/nechung_fortune.crontab @@ -3,5 +3,5 @@ # 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 diff --git a/infobase/configuration/cron/opensim_restart.crontab b/infobase/configuration/cron/opensim_restart.crontab index 8dc3ab0a..88c1a554 100644 --- a/infobase/configuration/cron/opensim_restart.crontab +++ b/infobase/configuration/cron/opensim_restart.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/configuration/cron/pack_feisty_for_web.crontab b/infobase/configuration/cron/pack_feisty_for_web.crontab index 1f90527c..83473f30 100644 --- a/infobase/configuration/cron/pack_feisty_for_web.crontab +++ b/infobase/configuration/cron/pack_feisty_for_web.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/configuration/cron/process_check.crontab b/infobase/configuration/cron/process_check.crontab index b88350d8..e0d76a25 100644 --- a/infobase/configuration/cron/process_check.crontab +++ b/infobase/configuration/cron/process_check.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/configuration/cron/random_sound.crontab b/infobase/configuration/cron/random_sound.crontab index 144e0778..31f894bf 100644 --- a/infobase/configuration/cron/random_sound.crontab +++ b/infobase/configuration/cron/random_sound.crontab @@ -1,4 +1,4 @@ #[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 diff --git a/infobase/configuration/cron/snarf_linux_configuration.crontab b/infobase/configuration/cron/snarf_linux_configuration.crontab index c670cb5f..e1096a06 100644 --- a/infobase/configuration/cron/snarf_linux_configuration.crontab +++ b/infobase/configuration/cron/snarf_linux_configuration.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/configuration/cron/synch_and_swim_downstream.crontab b/infobase/configuration/cron/synch_and_swim_downstream.crontab index f4fee134..d447b62e 100644 --- a/infobase/configuration/cron/synch_and_swim_downstream.crontab +++ b/infobase/configuration/cron/synch_and_swim_downstream.crontab @@ -4,5 +4,5 @@ # 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 diff --git a/infobase/configuration/cron/tell_zooty_our_ip.crontab b/infobase/configuration/cron/tell_zooty_our_ip.crontab index a6c31a1c..37322d24 100644 --- a/infobase/configuration/cron/tell_zooty_our_ip.crontab +++ b/infobase/configuration/cron/tell_zooty_our_ip.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/configuration/cron/time_synch.crontab b/infobase/configuration/cron/time_synch.crontab index 8b4ff038..17cdd554 100644 --- a/infobase/configuration/cron/time_synch.crontab +++ b/infobase/configuration/cron/time_synch.crontab @@ -2,13 +2,13 @@ #[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 diff --git a/infobase/configuration/cron/uptime_report.crontab b/infobase/configuration/cron/uptime_report.crontab index 1494c34c..3ee25494 100644 --- a/infobase/configuration/cron/uptime_report.crontab +++ b/infobase/configuration/cron/uptime_report.crontab @@ -1,5 +1,5 @@ #[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 diff --git a/infobase/fortunes.dat b/infobase/fortunes.dat index 0dd5b0a8..882681cf 100644 --- a/infobase/fortunes.dat +++ b/infobase/fortunes.dat @@ -42640,4 +42640,8 @@ effort are in the heap of wisdom awareness; 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 diff --git a/scripts/files/count_files.sh b/scripts/files/count_files.sh index b70d75f2..847fb68e 100644 --- a/scripts/files/count_files.sh +++ b/scripts/files/count_files.sh @@ -1,23 +1,27 @@ #!/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. -- 2.34.1