automated terminal push
This commit is contained in:
49
recycle/cron.bash
Executable file
49
recycle/cron.bash
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/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 yankee -l 2>/dev/null; echo "$cron_line") | crontab -u yankee -
|
||||
|
||||
echo "Cron job added for user $user:"
|
||||
|
||||
echo "$cron_line"
|
||||
|
||||
}
|
||||
|
||||
whoami
|
||||
|
||||
# Example usage:
|
||||
user="yankee"
|
||||
minute="*" # 4:20 PM
|
||||
hour="*" # 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="cd /yankee-gnome-fire-consumer/; /bin/bash consumer.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"
|
||||
Reference in New Issue
Block a user