A complete guide with examples, time customization, and process management
Sometimes you need to automate a task on a Linux server — but crontab isn’t available. This is common on restricted systems, containers, or environments where cron is not installed or disabled.
With a simple Bash loop, you can create your own lightweight scheduler that behaves similarly to cron.
This guide covers:
- How to build a Bash-based scheduler
- How to change the schedule time and day
- Example scripts
- Directory structure
- How to start, stop, and restart the scheduler
- Logging
- Notes about server timezone differences
Note: The Linux server time may be different from your local timezone. Always verify the server time with:
dateAdjust the scheduled time accordingly.
your-project/
│
├── master.sh
├── run_schedule.sh
└── scheduler.log # created after first run
This script is what you want to run on schedule.
#!/usr/bin/env bash
echo "Master script executed at $(date)" >> master.logThis script continuously checks the date and time.
It runs master.sh every Saturday at 06:00.
#!/usr/bin/env bash
cd "$(dirname "$0")"
SCRIPT="./master.sh"
while true; do
DOW=$(date +%u) # Day of week (1–7, Monday=1)
TIME=$(date +%H:%M) # Time in 24-hour format (HH:MM)
if [[ "$DOW" == "6" && "$TIME" == "06:00" ]]; then
echo "Running master.sh at $(date)"
bash "$SCRIPT"
sleep 60 # Prevent running twice in the same minute
fi
sleep 20
doneThe scheduler uses two conditions:
- DOW → Day of week
- TIME → Exact time (HH:MM)
The command date +%u returns:
| Value | Day |
|---|---|
| 1 | Monday |
| 2 | Tuesday |
| 3 | Wednesday |
| 4 | Thursday |
| 5 | Friday |
| 6 | Saturday |
| 7 | Sunday |
Run every Monday at 06:00:
if [[ "$DOW" == "1" && "$TIME" == "06:00" ]]; thenRun every Wednesday at 06:00:
if [[ "$DOW" == "3" && "$TIME" == "06:00" ]]; thenRun every Sunday at 06:00:
if [[ "$DOW" == "7" && "$TIME" == "06:00" ]]; thenTime is checked using:
TIME=$(date +%H:%M)This is 24-hour format.
Run at 07:30 AM:
if [[ "$TIME" == "07:30" ]]; thenRun at 11:45 PM (23:45):
if [[ "$TIME" == "23:45" ]]; thenRun at midnight:
if [[ "$TIME" == "00:00" ]]; thenExample: Run at 06:00 and 18:00 on Saturday:
if [[ "$DOW" == "6" && ( "$TIME" == "06:00" || "$TIME" == "18:00" ) ]]; thenRemove the DOW check:
if [[ "$TIME" == "06:00" ]]; thenif [[ "$(date +%M)" == "00" ]]; thenGive execute permissions:
chmod +x master.sh
chmod +x run_schedule.shStart it using nohup so it survives logout:
nohup ./run_schedule.sh > scheduler.log 2>&1 &pgrep -fl run_schedule.shOr:
ps aux | grep run_schedule.shKill by name:
pkill -f run_schedule.shOr kill by process ID:
ps aux | grep run_schedule.sh
kill <PID>Force kill:
kill -9 <PID>pkill -f run_schedule.sh
nohup ./run_schedule.sh > scheduler.log 2>&1 &tail -f scheduler.logThis method lets you schedule tasks without relying on cron.
By adjusting the DOW and TIME variables, you can create almost any schedule you want — daily tasks, weekly tasks, specific hours, or multiple run times.