crontab called reset_can.sh also required /etc/sudoers enabled

This commit is contained in:
R.P. Clark 2025-01-20 10:37:46 +00:00
parent 96d3651d95
commit ae790faf89
2 changed files with 64 additions and 0 deletions

25
can_logging/crontab.list Normal file
View File

@ -0,0 +1,25 @@
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
25 8 * * * /home/robin/reset_can.sh >> /home/robin/can_logs/cronlog.log 2>&1
#34 10 * * * /home/robin/reset_can.sh >> /home/robin/can_logs/cronlog.log 2>&1

39
can_logging/reset_can.sh Executable file
View File

@ -0,0 +1,39 @@
#!/bin/bash
# crontab starts bash minimally, so
export PATH=/usr/local/bin:/usr/bin:/bin
# debugging
set -eux
sudo ip link set can0 down || { echo "Failed to bring down CAN interface"; exit 1; }
# NON FD or classical only set up
# sudo ip link set can0 type can bitrate 100000 sjw 128
sudo ip link set can0 type can bitrate 100000 sjw 128 dbitrate 400000 fd on
sudo ip link set can0 up
mkdir -p ~/can_logs
cd ~/can_logs/
d=`date`
echo "-----------------------------------------------------------" >> can_reset_log.txt
/usr/sbin/ifconfig can0 >> can_reset_log.txt
echo "CAN NOW RESET" $d >> can_reset_log.txt
sudo ip link show can0 >> can_reset_log.txt
echo "-----------------------------------------------------------" >> can_reset_log.txt
# Compress any old log files
#
find . -type f -name "*.log" -exec zip {}.zip {} \;
# delete uncompressed log files
find . -type f -name "*.log" -exec rm -f {} \;
/usr/bin/candump -l -t A can0 &
# Find and delete .log.zip files older than one month
#
find . -type f -name "*.log.zip" -mtime +30 -exec rm -f {} \;