3
I want to schedule the crontab
through a script.sh
.
I tried to add the following line inside the script.sh
:
echo "00 01 * * * retag /retag/licenca.sh" >> /etc/crontab
It worked, but he adds a line each time the script runs. I need him to book one time and only.
How to solve this?
I need to schedule this file in many places and at the same time, so the question, wanted a way to expedite the process.
With the
>>
it adds the output of the command at the end of the file. With the>
it rewrites the file only with the output content of the command.– Camilo Santos
but then it erases everything I already have scheduled correctly? I need to put at the end of the file without replacing what already has!
– Moises Pequeno
the end will always be
retag /retag/licenca.sh
? From what I understand you need that when you run the script if there is this line it only changes the schedule time and the rest of the/etc/crontab
remain intact, would that?– Camilo Santos
Yes, the end will always be retag /retag/licenca.sh ! I wouldn’t want the script to insert that line inside the crontab the first time it runs, the second time the script runs, if it already has that line inside it does nothing!
– Moises Pequeno
The way I said it in the question it’s working, but every time the script runs it adds this line again! That is, if I schedule it to run once a day for 30 days it will generate 30 lines within the crontab!
– Moises Pequeno
sed -i 's/.*retag \/retag\/licenca.sh/30 13 * * * retag \/retag\/licenca.sh/' /temp/crontab
does a test with this command... only changes the path to the file at the end, I copied the crontab to another directory to test– Camilo Santos