Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
66
rated 0 times [  66] [ 0]  / answers: 1 / hits: 65450  / 2 Years ago, thu, december 9, 2021, 8:45:30

Is there a way to add lines to a user's cron via script?



I usually do it using crontab -e, but I would like to automate this task with a shell script.


More From » scripts

 Answers
5

You can echo the line in to the bottom of the current users crontab like this:


#!/bin/bash

line="* * * * * /path/to/command"
(crontab -u $(whoami) -l; echo "$line" ) | crontab -u $(whoami) -

[#43733] Thursday, December 9, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kilusy

Total Points: 171
Total Questions: 110
Total Answers: 128

Location: Cayman Islands
Member since Sat, Dec 5, 2020
3 Years ago
;