I need to add a cron job thru a script I run to set up a server. I am currently using Ubuntu. I can use crontab -e
but that will open an editor to edit the curr
Even more simple answer to you question would be:
echo "0 1 * * * /root/test.sh" | tee -a /var/spool/cron/root
You can setup cronjobs on remote servers as below:
#!/bin/bash
servers="srv1 srv2 srv3 srv4 srv5"
for i in $servers
do
echo "0 1 * * * /root/test.sh" | ssh $i " tee -a /var/spool/cron/root"
done
In Linux, the default location of the crontab
file is /var/spool/cron/
. Here you can find the crontab
files of all users. You just need to append your cronjob entry to the respective user's file. In the above example, the root user's crontab file is getting appended with a cronjob to run /root/test.sh
every day at 1 AM.