diff options
| author | hc <hc@email.ch> | 2025-02-01 11:07:07 +0800 |
|---|---|---|
| committer | hc <hc@email.ch> | 2025-02-01 11:07:07 +0800 |
| commit | 8c1a40d00ca69f2194a9f7c4cf4e884a2d225d3d (patch) | |
| tree | 2c880e936b465915ea6483fe2737a55b9638923b /cron_setup.sh | |
| parent | 6e2bd1f5053f5244d1294ba5ae2c0ffc047743b6 (diff) | |
formatednicely
Diffstat (limited to 'cron_setup.sh')
| -rwxr-xr-x | cron_setup.sh | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/cron_setup.sh b/cron_setup.sh new file mode 100755 index 0000000..ca2fdbd --- /dev/null +++ b/cron_setup.sh | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | # add client_manager python to crontab | ||
| 4 | |||
| 5 | if [ "$EUID" -ne 0 ]; then | ||
| 6 | echo "ERROR: This script must be run as root" | ||
| 7 | exit 1 | ||
| 8 | fi | ||
| 9 | |||
| 10 | # Get script's directory | ||
| 11 | SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
| 12 | |||
| 13 | # Create a temporary file with the cron entry | ||
| 14 | echo "@reboot /usr/bin/python3 $SCRIPT_DIR/client_manager.py" > temp_cron | ||
| 15 | |||
| 16 | # Append this to the user's crontab | ||
| 17 | crontab -l > current_cron 2>/dev/null || true # Get current crontab or empty if none exists | ||
| 18 | cat temp_cron >> current_cron | ||
| 19 | crontab current_cron | ||
| 20 | |||
| 21 | # Clean up temporary files | ||
| 22 | rm temp_cron current_cron | ||
