* Suggestion: Add run-parts to Cygwin.
@ 2021-06-29 8:10 Joe Smith
0 siblings, 0 replies; only message in thread
From: Joe Smith @ 2021-06-29 8:10 UTC (permalink / raw)
To: cygwin
[-- Attachment #1: Type: text/plain, Size: 606 bytes --]
The gist is that one can use Windows Task Manager to start a single
bash script with elevated privileges and that script can run the scripts
in a given directory, with elevated privileges. Various Linux
distributions use /etc/cron.{daily,weekly,monthly} for this purpose.
$ head -5 /usr/bin/run-parts
#!/bin/bash# Name: /usr/bin/run-parts Modified by Joe Smith
(joeinwap,gmail)
# Purpose: Runs jobs sequentially at regular intervals
(daily,weekly,monthly)# Concept taken from Debian, copied from RHEL-5,
modified for Cygwin.
# See end for "How to run cron jobs with elevated privs on Cygwin".
[-- Attachment #2: run-parts.txt --]
[-- Type: text/plain, Size: 3459 bytes --]
#!/bin/bash
# Name: /usr/bin/run-parts Modified by Joe Smith (joeinwap,gmail)
# Purpose: Runs jobs sequentially at regular intervals (daily,weekly,monthly)
# Concept taken from Debian, copied from RHEL-5, modified for Cygwin.
# See end for "How to run cron jobs with elevated privs on Cygwin".
### Set ENV to run under Windows Task Scheduler ###
export SHELL=/bin/bash
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
export MAILTO=root # See also /etc/ssmtp/ssmtp.conf
export HOME=/root
export USER=root
# keep going when something fails
set +e
if [ $# -lt 1 ]; then
echo "Usage: run-parts <dir>"
exit 1
fi
if [ ! -d $1 ]; then
echo "Not a directory: $1"
exit 1
fi
### Log STDOUT and STDERR since Task Scheduler is not the same as crond.
LOGFILE=/var/log/cron.log
TMPFILE=/var/log/run-parts.log
exec </dev/null >>$TMPFILE 2>&1
# Ignore *~ and *, scripts
start_time=`date`
for i in $1/*[^~,] ; do
[ -d $i ] && continue
# Don't run *.{rpmsave,rpmorig,rpmnew,swp} scripts
[ "${i%.rpmsave}" != "${i}" ] && continue
[ "${i%.rpmorig}" != "${i}" ] && continue
[ "${i%.rpmnew}" != "${i}" ] && continue
[ "${i%.swp}" != "${i}" ] && continue
[ "${i%,v}" != "${i}" ] && continue
if [ -x $i ]; then
$i 2>&1 | awk -v "progname=$i" \
'progname {
print progname ":\n"
progname="";
}
{ print; }'
fi
done
end_time=`date` # Merge tmp log with /var/log/cron
if [ -s $TMPFILE ]; then
echo "Started: $start_time" >> $LOGFILE
cat $TMPFILE >> $LOGFILE
echo "Finished: $end_time" >> $LOGFILE
echo "" >> $LOGFILE
: > $TMPFILE
fi
exit 0
cat <<'EOM'
"How to run cron jobs with elevated privs on Cygwin".
This procedure has been used with Cygwin running on Vista or Windows 7, 10.
# Here is an example of a Linux-style /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
#1 * * * * root run-parts /etc/cron.hourly
02 22 * * * root run-parts /etc/cron.daily
22 22 * * 0 root run-parts /etc/cron.weekly
42 22 1 * * root run-parts /etc/cron.monthly
###########################################
The second column (hours) is 4 for Linux, which is fine for servers, but
for laptops, values like 0 (midnight) or 22 (10pm) may be more appropriate.
Start -> All Programs -> Accessories -> System Tools -> Task Scheduler
Task Scheduler: Create Basic Task (do this 3 times)
Name: cron-daily, cron-weekly, or cron-monthly
Description: Runs cygwin programs with elevated privs.
Trigger:
Daily, 10:02:00pm, recur every 1 days
Weekly, 10:22:00pm, recur every 1 weeks on Sunday
Monthly, 10:42:00pm, recur all months on the 1st
Action: Start a program
Program: C:\cygwin64\bin\bash.exe
Arguments: /usr/bin/run-parts /etc/cron.daily
or: /usr/bin/run-parts /etc/cron.weekly
or: /usr/bin/run-parts /etc/cron.monthly
Start in: C:\cygwin64\bin
Finish: Open the Properties dialog when finished.
General:
Run whether user is logged on or not
Do not store password
Run with highest privileges
Conditions:
Wake the computer to run this task
Settings:
Run task as soon as possible after a scheduled start is missed
Stop the task if it runs longer than: 1 hour
Populate the directories with shell scripts or symlinks to binaries.
ln -s /usr/bin/updatedb /etc/cron.daily
I used "ln -s /usr/bin/run-parts /etc/cron-parts" so that this
file can be easily found using "ls -l /etc/cron*".
joeinwap,gmail
EOM
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-06-29 8:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-29 8:10 Suggestion: Add run-parts to Cygwin Joe Smith
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).