Skip to content

Instantly share code, notes, and snippets.

@PSJoshi
Created August 17, 2022 12:33
Show Gist options
  • Save PSJoshi/d0d289294bc45cf5cabacd55818044f7 to your computer and use it in GitHub Desktop.
Save PSJoshi/d0d289294bc45cf5cabacd55818044f7 to your computer and use it in GitHub Desktop.
Cron job using bash script
### Cron job using bash script
```
#!/bin/sh
crontab -l > cron_backup
echo "0 10 * * * sudo /home/<user>/job.sh >/dev/null 2>&1" >> cron_backup
crontab cron_backup
rm cron_backup
```
Another version
```
#!/bin/bash
(crontab -l; echo "0 10 * * * /home/<user>/job.sh") | sort -u | crontab -
```
Ref - https://www.baeldung.com/linux/create-crontab-script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment