1. 程式人生 > >ubuntu 定時、開機啟動例子

ubuntu 定時、開機啟動例子

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.


SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin


# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
*/1 * * * *     root    date >> /home/time.log  
*/5 * * * *     root    /usr/share/nginx/sh/du.sh #定時分鐘執行du.sh
#
"/etc/crontab" 17L, 817C 

service cron restart
service cron start
service cron stop
#du.sh
#!/bin/bash

IFS=':'

#echo "Employee Names:"

#echo "---------------"

while read name empid dept

do
                if [ ! $name ]; then
                                echo date >>/usr/share/nginx/sh/du.log
                         echo "IS NULL" >> /usr/share/nginx/sh/du.log
                else
                        echo date >> /usr/share/nginx/sh/du.log
                        echo "$name is part of $name department">> /usr/share/nginx/sh/du.log
                        mkdir /usr/share/nginx/www/files/ws/video/videolist/$name
                        ffmpeg -i /usr/share/nginx/www/files/ws/video/tmpvideo/$name -y -ab 32 -ar 22050 -qscale 10 -s 640*480 -r 15 /usr/share/nginx/www/files/ws/video/videolist/$name/index.mp4
                       sed -i '1d' /usr/share/nginx/sh/record.txt
                       rm -rf /usr/share/nginx/www/files/ws/video/tmpvideo/$name
                        break
                fi

done < /usr/share/nginx/sh/record.txt
exit 0

在/etc/init.d/rc.local中設定開機啟動