Task execution timing (the crontab) normal user

Task execution timing (the crontab) normal user

(Run the following command as root)
1, a regular user opens a timed task test1

crontab -e -u test1

Here Insert Picture Description
2, the timing task is to execute a shell script, usertest.sh as follows, by the way print execution time:

#!/bin/bash
declare -i i=0
while ((i<=2))
do
    echo "Normal user can perform crontab!!! >>/home/test1/printcontent.txt
    let i++
done

time1=$(date "+%Y-%m-%d %H:%M:%S")
echo $time1

3, will be the owner of all the relevant documents to the scheduled tasks set to the user test1

chown -R test1:test1 /home/test1/

4, you can view the log, e-mail, to see the implementation (Each time scheduled tasks will send a message to the user's mailbox):
View timed log:

tail -f /var/log/cron

Test1 view the user's mailbox, print the script execution time, error-free, that is, to perform regular tasks successfully:

tail -f /var/spool/mail/test1

Here Insert Picture Description
Note:
When the program after you perform the specified time, the system will send a message to you, to display the contents of the program execution, if you do not wish to receive such a letter, add a space after each line grid> / dev / null 2> & 1 .

Published 12 original articles · won praise 0 · Views 343

Guess you like

Origin blog.csdn.net/Junetest/article/details/104796050