version=pmwiki-2.2.130 ordered=1 urlencoded=1 agent=Mozilla/5.0 (X11; Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0 author=pyr3x charset=UTF-8 csum= ctime=1641008430 host=24.97.51.2 name=Pkgadd.CheckUpdates rev=7 targets= text=(:title Checking for package updates via cron(8):)%0a%0aSimilar to syspatch(8) with the -c switch, the following script supports checking for updates to packages suitable for cron(8).%0a%0aThis script will run 'pkg_add -Uun' to determine which packages would have been updated and stores the result. It then removes packages starting with 'quirks' (a required package on OpenBSD) and determines how many remain. If there are no packages, return 0, otherwise, echo the package names and return 2. Returning 0 or 2 is significant because crontab(5) with the -n switch determines whether to send mail. Since we are likely to run this nightly, we do not want to flood our inbox with output from cron when there is no action to take. By exiting with a non-zero (2) exit status when there are packages, we can ensure we only get email if there are package updates. %0a%0a[@%0a#!/bin/ksh%0aPACKAGES=`/usr/sbin/pkg_add -Uun`%0aNOQUIRKS=`/bin/echo $PACKAGES | grep -e '^quirks' -v | /usr/bin/wc -l`%0aif [ "$NOQUIRKS" -eq "0" ]; then%0a /bin/echo "No package updates available%0a return 0%0aelse%0a /bin/echo $PACKAGES%0a return 2%0afi%0a@]%0a%0aSave the above script to '/usr/local/bin/pkg_update' and run the following commands for the proper user/group ownership and permissions.%0a%0a[@%0a$ doas chmod 755 /usr/local/bin/pkg_update%0a$ doas chown root:bin /usr/local/bin/pkg_update%0a@]%0a%0aWe now need to add it to root's crontab.%0a%0a[@%0a$ doas crontab -e%0a@]%0a%0aAt the bottom add the following line:%0a%0a[@%0a0 0 * * * -ns /usr/local/bin/pkg_update%0a@]%0a%0aNotice the -n switch to not mail on a successful run. We have purposefully setup the script to have a non-successful (non-zero) exit when there are no packages to update thus generating the email.%0a%0aYou may also opt to add this script to /etc/daily.local with the single line:%0a%0a[@%0a/usr/local/bin/pkg_update%0a@]%0a%0aHowever, it should be noted that this script is designed with return values for direct use in crontab. If being called from the /etc/daily script, you'll likely want to add some additional messages to be echoed either in the script directly or in /etc/daily.local.%0a%0aIt is highly recommended to setup a user account where root's email can be forwarded. See afterboot(8) section 'Mail aliases'.%0a time=1641011342 title=Checking for package updates via cron(8) author:1641011342=pyr3x diff:1641011342:1641010666:=5,6c5,6%0a%3c This script will run 'pkg_add -Uun' to determine which packages would have been updated and stores the result. It then removes packages starting with 'quirks' (a required package on OpenBSD) and determines how many remain. If there are no packages, return 0, otherwise, echo the package names and return 2. Returning 0 or 2 is significant because crontab(5) with the -n switch determines whether to send mail. Since we are likely to run this nightly, we do not want to flood our inbox with output from cron when there is no action to take. By exiting with a non-zero (2) exit status when there are packages, we can ensure we only get email if there are package updates. %0a%3c %0a---%0a> This script will run 'pkg_add -Uun' to determine which packages would have been updated and stores the result. It then removes packages starting with 'quirks' (a required package on OpenBSD) and determines how many remain. If there are no packages, return 0, otherwise, echo the package names and return 1. Returning 0 or 1 is significant because crontab(5) with the -n switch determines whether to send mail. Since we are likely to run this nightly, we do not want to flood our inbox with output from cron when there is no action to take. By exiting with a non-zero (1) exit status when there are packages, we can ensure we only get email if there are package updates. %0a> %0a12d11%0a%3c /bin/echo "No package updates available%0a16c15%0a%3c return 2%0a---%0a> return 1%0a39c38%0a%3c Notice the -n switch to not mail on a successful run. We have purposefully setup the script to have a non-successful (non-zero) exit when there are no packages to update thus generating the email.%0a---%0a> Notice the -n switch to not mail on a successful run. We have purposefully setup the script to have a non-successful (non-zero) exit when there are no packages to update -- thus generating the email.%0a host:1641011342=24.97.51.2 author:1641010666=pyr3x diff:1641010666:1641010044:=46c46%0a%3c However, it should be noted that this script is designed with return values for direct use in crontab. If being called from the /etc/daily script, you'll likely want to add some additional messages to be echoed either in the script directly or in /etc/daily.local.%0a---%0a> However, it should be noted that this script is designed with return values for direct use in crontab. If being called from the /etc/rc.daily script, you'll likely want to add some additional messages to be echoed either in the script directly or in /etc/daily.local.%0a host:1641010666=24.97.51.2 author:1641010044=pyr3x diff:1641010044:1641010030:=42c42%0a%3c [@%0a---%0a> {@%0a host:1641010044=24.97.51.2 author:1641010030=pyr3x diff:1641010030:1641009884:=33d32%0a%3c %0a39,46d37%0a%3c %0a%3c You may also opt to add this script to /etc/daily.local with the single line:%0a%3c %0a%3c {@%0a%3c /usr/local/bin/pkg_update%0a%3c @]%0a%3c %0a%3c However, it should be noted that this script is designed with return values for direct use in crontab. If being called from the /etc/rc.daily script, you'll likely want to add some additional messages to be echoed either in the script directly or in /etc/daily.local.%0a host:1641010030=24.97.51.2 author:1641009884=pyr3x diff:1641009884:1641008683:=5,6d4%0a%3c This script will run 'pkg_add -Uun' to determine which packages would have been updated and stores the result. It then removes packages starting with 'quirks' (a required package on OpenBSD) and determines how many remain. If there are no packages, return 0, otherwise, echo the package names and return 1. Returning 0 or 1 is significant because crontab(5) with the -n switch determines whether to send mail. Since we are likely to run this nightly, we do not want to flood our inbox with output from cron when there is no action to take. By exiting with a non-zero (1) exit status when there are packages, we can ensure we only get email if there are package updates. %0a%3c %0a17,39c15%0a%3c @]%0a%3c %0a%3c Save the above script to '/usr/local/bin/pkg_update' and run the following commands for the proper user/group ownership and permissions.%0a%3c %0a%3c [@%0a%3c $ doas chmod 755 /usr/local/bin/pkg_update%0a%3c $ doas chown root:bin /usr/local/bin/pkg_update%0a%3c @]%0a%3c %0a%3c We now need to add it to root's crontab.%0a%3c %0a%3c [@%0a%3c $ doas crontab -e%0a%3c @]%0a%3c %0a%3c At the bottom add the following line:%0a%3c [@%0a%3c 0 0 * * * -ns /usr/local/bin/pkg_update%0a%3c @]%0a%3c %0a%3c Notice the -n switch to not mail on a successful run. We have purposefully setup the script to have a non-successful (non-zero) exit when there are no packages to update -- thus generating the email.%0a%3c %0a%3c It is highly recommended to setup a user account where root's email can be forwarded. See afterboot(8) section 'Mail aliases'.%0a---%0a> @]%0a\ No newline at end of file%0a host:1641009884=24.97.51.2 author:1641008683=pyr3x diff:1641008683:1641008430:=1,5d0%0a%3c (:title Checking for package updates via cron(8):)%0a%3c %0a%3c Similar to syspatch(8) with the -c switch, the following script supports checking for updates to packages suitable for cron(8).%0a%3c %0a%3c [@%0a14,15c9%0a%3c fi%0a%3c @]%0a\ No newline at end of file%0a---%0a> fi%0a\ No newline at end of file%0a host:1641008683=24.97.51.2 author:1641008430=pyr3x diff:1641008430:1641008430:=1,9d0%0a%3c #!/bin/ksh%0a%3c PACKAGES=`/usr/sbin/pkg_add -Uun`%0a%3c NOQUIRKS=`/bin/echo $PACKAGES | grep -e '^quirks' -v | /usr/bin/wc -l`%0a%3c if [ "$NOQUIRKS" -eq "0" ]; then%0a%3c return 0%0a%3c else%0a%3c /bin/echo $PACKAGES%0a%3c return 1%0a%3c fi%0a\ No newline at end of file%0a host:1641008430=24.97.51.2