diff --git a/createfile.py b/createfile.py new file mode 100644 index 0000000..83104e3 --- /dev/null +++ b/createfile.py @@ -0,0 +1,12 @@ +from datetime import date + +def createfile(): + filenames = ["1Start","2Middle","3End"] + todaystr = date.today().strftime("%y%m%d") + if date.today().weekday() < 5: + for filename in filenames: + with open("journal/"+todaystr+"_"+filename,"w") as fh: + pass + +if __name__ == '__main__': + createfile() diff --git a/systemd_timer_files/pythoncreatelog.service b/systemd_timer_files/pythoncreatelog.service new file mode 100644 index 0000000..23434a9 --- /dev/null +++ b/systemd_timer_files/pythoncreatelog.service @@ -0,0 +1,9 @@ +[Unit] +Description="Executes the script that creates the log files needed for today" + +[Service] +WorkingDirectory=[[path_to_repo]] +ExecStart=[[path_to_repo]]/.venv/bin/python3 [[path_to_repo]]/createfile.py + +[Install] +WantedBy=default.target diff --git a/systemd_timer_files/pythoncreatelog.timer b/systemd_timer_files/pythoncreatelog.timer new file mode 100644 index 0000000..641fdf2 --- /dev/null +++ b/systemd_timer_files/pythoncreatelog.timer @@ -0,0 +1,9 @@ +[Unit] +Description="Create the logfiles of today" + +[Timer] +OnBootSec=1min +Unit=pythoncreatelog.service + +[Install] +WantedBy=default.target diff --git a/systemd_timer_files/settimer.sh b/systemd_timer_files/settimer.sh index 0a7e8aa..9c76842 100644 --- a/systemd_timer_files/settimer.sh +++ b/systemd_timer_files/settimer.sh @@ -10,6 +10,20 @@ replace_and_move() { echo "$1 script placed at $OUTDIR" } +setfile() { + TIMERNAME="$1.timer" + SERVICENAME="$1.service" + replace_and_move $TIMERNAME $MAPPATH + replace_and_move $SERVICENAME $MAPPATH + echo "Reload systemd deamon" + `systemctl --user daemon-reload` + echo "Enable $TIMERNAME for systemd" + `systemctl --user enable $TIMERNAME` + echo "Start $TIMERNAME for systemd" + `systemctl --user start $TIMERNAME` +} + + ################### # START OF SCRIPT # ################### @@ -36,20 +50,11 @@ else exit fi -FILENAME="pythontaskcheck" FOLDERNAME="systemd_timer_files" MAPPATH="$GIT_DIR/$FOLDERNAME/" -TIMERNAME="$FILENAME.timer" -SERVICENAME="$FILENAME.service" -replace_and_move $TIMERNAME $MAPPATH -replace_and_move $SERVICENAME $MAPPATH - -echo "Reload systemd deamon" -`systemctl --user daemon-reload` -echo "Enable $TIMERNAME for systemd" -`systemctl --user enable $TIMERNAME` -echo "Start $TIMERNAME for systemd" -`systemctl --user start $TIMERNAME` +setfile "pythontaskcheck" +setfile "pythoncreatelog" +