From 9e771bff8aaa70a49dcff575ac7024e071766e34 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 7 Feb 2025 14:34:54 -0500 Subject: [PATCH] automated terminal push --- cron.bash | 46 ++++++++++++++++++++++++++++++++++++++++++++++ provision.bash | 6 +++++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 cron.bash diff --git a/cron.bash b/cron.bash new file mode 100755 index 0000000..f1b7f9d --- /dev/null +++ b/cron.bash @@ -0,0 +1,46 @@ +#!/bin/bash + +# Function to create a cron job +create_cron_job() { + user=$1 # Username for the cron job + minute=$2 # Minute of the hour (0-59) + hour=$3 # Hour of the day (0-23) + day_of_month=$4 # Day of the month (1-31) + month=$5 # Month of the year (1-12) + day_of_week=$6 # Day of the week (0-6, Sunday is 0) + command=$7 # Command to execute + + # Construct the cron job line + cron_line="${minute} ${hour} ${day_of_month} ${month} ${day_of_week} ${command}" + + # Add the cron job for the specified user. Redirects stderr to stdout. + (crontab -u "$user" -l 2>/dev/null; echo "$cron_line") | crontab -u "$user" - + + echo "Cron job added for user $user:" + echo "$cron_line" +} + +whoami + +# Example usage: +user="yankee" +minute="20" # 4:20 PM +hour="16" # 4 PM in 24-hour format +day_of_month="*" # Every day of the month +month="*" # Every month +day_of_week="*" # Every day of the week +command="/tmp/file.bash" + +create_cron_job "$user" "$minute" "$hour" "$day_of_month" "$month" "$day_of_week" "$command" + + +# Example with different schedule (e.g., every Monday at 2:00 AM): +# user="yankee" +# minute="0" +# hour="2" +# day_of_month="*" +# month="*" +# day_of_week="1" # Monday (0 is Sunday, 1 is Monday, etc.) +# command="/tmp/another_script.sh" + +# create_cron_job "$user" "$minute" "$hour" "$day_of_month" "$month" "$day_of_week" "$command" \ No newline at end of file diff --git a/provision.bash b/provision.bash index 08185fc..2d0f3c8 100644 --- a/provision.bash +++ b/provision.bash @@ -9,7 +9,7 @@ set +x ## echo "##" -echo "## launch > provision situation #2" +echo "## launch > provision situation #3" echo "##" ##sudo apt update; @@ -23,3 +23,7 @@ pip install selenium ## for rest situations pip install requests + +sudo apt install cron -y + +bash cron.bash \ No newline at end of file