我想设置cron tab job [英] i want to set cron tab job

查看:85
本文介绍了我想设置cron tab job的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在为cron tab job编写脚本bt我得到权限被拒绝错误我在这里复制了我的代码

plz告诉我它有什么问题



Hi,

I am writing script for cron tab job bt i get permission denied error i am copied my code here
plz tell me anything wrong in it

#!/bin/bash
# Author: Anand Subramanian
# Publisher: http://LinuXplained.com
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

#############BEGIN EDIT AREA######################
# BELOW ARE SOME REQUIRED SETTINGS. CONFIGURE THEM PROPERLY BEFORE USING
# THE SCRIPT

# DBHOSTNAME is the host name of the host that hosts yours MySQL database. 
# You can get this from GoDaddy. Just replace the entire contents after =
# with your database host name.  
#DBHOSTNAME=xxxxx.db.xxxxxxx.hostedresource.com
DBHOSTNAME=ide1311612102067.db.9968868.hostedresource.com
# DBUSERNAME is the username to access the MySQL database. Just replace 
# the word databaseusername below with your username. No 
# quotes needed.
#DBUSERNAME=databaseusername
DBUSERNAME=ide1311612102067

# DBPASSWORD is the password to access the MySQL database. Just replace 
# the word databasepassword below with your password database. No 
# quotes needed.
#DBPASSWORD=databasepassword
DBPASSWORD=Welcome1!

# DBNAME is the MySQL database that needs to be backed up. Typically, in 
# GoDaddy Linux Hosting this is  the same as the DBUSERNAME
DBNAME=ide1311612102067

# Path of the folder where backups will be stored. $HOME/html will
# automatically put you in the hosting accounts root folder. GoDaddy MySQL 
# databases are normally stored in the _db_backups folder within your base 
# hosting folder. If the folder does not exist create it before running the 
# script. You can also create a subfolder within _db_backups folder if you 
# would like to backup the database to a separate folder. Alternatively, 
# you can backup to an entirely different folder of your choice. Whatever 
# you choose to do, ensure that the path is correctly specified below. 
#BACKUPFOLDER=$HOME/html/_db_backups/backupfolder
BACKUPFOLDER=$HOME/html/sampledb_backup

# Should the script delete older files based on the conditions you set 
# below (Y or N - uppercase letters only). Choosing Y will maintain only
# recent backups based on your settings below. Choosing N will keep all
# the backups from the past. 
DELETEFILES=Y

# Do daily backups Y or N? (one uppercase letter only)
DAILYBACKUP=Y

# Number of recent daily backups to keep. The default is 6 (Sun-Fri) with 
# Weekly backup on Sat.All previous backups will be deleted. This is 
# meaningless unless DAILYBACKUP is set to Y.
NUMDAILYBACKUPS=6

# Do weekly backups Y or N? (one uppercase letter only). Weekly backups
# are done on Saturdays.
WEEKLYBACKUP=Y

# Number of recent weekly backups to keep. The default is 4. All previous 
# weekly backups will be deleted. This is meaningless unless WEEKLYBACKUP 
# is set to Y.
NUMWEEKLYBACKUPS=4

# Do monthly backups Y or N? (one uppercase letter only). Monthly backups
# are done on the last day of the month.
MONTHLYBACKUP=Y

# Number of recent monthly backups to keep. The default is 2. All previous 
# monthly backups will be deleted. This is meaningless unless 
# MONTHLYBACKUP is set to Y.
NUMMONTHLYBACKUPS=2

umask nnn
#chmod 777 db_backup 
chmod u+rwx sampledb_backup
chmod a+x mysqlbackup_script.sh
chmod u+x mysqlbackup_script.sh

cat >/var/log/wtmp
cat >var/run/utmp

#chmod 777 mysqlbackup_script.sh
#############END EDIT AREA######################
#
# DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING. 
# WHILE YOU CAN EDIT IT TO CUSTOMIZE HOW THE SCRIPT WORKS, DOING SO CAN 
# BREAK THE FUNCTIONING OF THIS SCRIPT. 
#

TODATE=$(date +%d)
TOMORROW=`date +%d -d "1 day"`
TODAY=$(date +%a)
MONTH=$(date +%B)
WEEK=$(date +%U)

if [ $TODATE -gt $TOMORROW ] && [ "$MONTHLYBACKUP" == "Y" ]
then
	/usr/bin/mysqldump -h $DBHOSTNAME -u $DBUSERNAME -p$DBPASSWORD $DBNAME  | gzip > $BACKUPFOLDER/$DBNAME'_'`date '+%m-%d-%Y'`'_'$MONTH.sql.gz
else
	if [ "$TODAY" == "Sat" ] && [ "$WEEKLYBACKUP" == "Y" ]
	then
		/usr/bin/mysqldump -h $DBHOSTNAME -u $DBUSERNAME -p$DBPASSWORD $DBNAME  | gzip > $BACKUPFOLDER/$DBNAME'_'`date '+%m-%d-%Y'`'_'Week$WEEK.sql.gz
	else 
        if [ "$DAILYBACKUP" == "Y" ] 
		then
			/usr/bin/mysqldump -h $DBHOSTNAME -u $DBUSERNAME -p$DBPASSWORD $DBNAME  | gzip > $BACKUPFOLDER/$DBNAME'_'`date '+%m-%d-%Y'`'_'$TODAY.sql.gz
		fi
	fi
fi


if [ "$DELETEFILES" == "Y" ]
then
    NUMWEEKLY=$[$NUMWEEKLYBACKUPS*7]
    NUMMONTHLY=$[$NUMMONTHLYBACKUPS*31]
    find $BACKUPFOLDER/*Sun.sql.gz -type f -mtime +$NUMDAILYBACKUPS -delete 2> /dev/null
    find $BACKUPFOLDER/*Mon.sql.gz -type f -mtime +$NUMDAILYBACKUPS -delete 2> /dev/null
    find $BACKUPFOLDER/*Tue.sql.gz -type f -mtime +$NUMDAILYBACKUPS -delete 2> /dev/null
    find $BACKUPFOLDER/*Wed.sql.gz -type f -mtime +$NUMDAILYBACKUPS -delete 2> /dev/null
    find $BACKUPFOLDER/*Thu.sql.gz -type f -mtime +$NUMDAILYBACKUPS -delete 2> /dev/null
    find $BACKUPFOLDER/*Fri.sql.gz -type f -mtime +$NUMDAILYBACKUPS -delete 2> /dev/null
    find $BACKUPFOLDER/*Sat.sql.gz -type f -mtime +$NUMDAILYBACKUPS -delete 2> /dev/null
    find $BACKUPFOLDER/*Week*.sql.gz -type f -mtime +$NUMWEEKLY -delete 2> /dev/null
    find $BACKUPFOLDER/*January.sql.gz -type f -mtime +$NUMMONTHLY -delete 2> /dev/null
    find $BACKUPFOLDER/*February.sql.gz -type f -mtime +$NUMMONTHLY -delete 2> /dev/null
    find $BACKUPFOLDER/*March.sql.gz -type f -mtime +$NUMMONTHLY -delete 2> /dev/null
    find $BACKUPFOLDER/*April.sql.gz -type f -mtime +$NUMMONTHLY -delete 2> /dev/null
    find $BACKUPFOLDER/*May.sql.gz -type f -mtime +$NUMMONTHLY -delete 2> /dev/null
    find $BACKUPFOLDER/*June.sql.gz -type f -mtime +$NUMMONTHLY -delete 2> /dev/null
    find $BACKUPFOLDER/*July.sql.gz -type f -mtime +$NUMMONTHLY -delete 2> /dev/null
    find $BACKUPFOLDER/*August.sql.gz -type f -mtime +$NUMMONTHLY -delete 2> /dev/null
    find $BACKUPFOLDER/*September.sql.gz -type f -mtime +$NUMMONTHLY -delete 2> /dev/null
    find $BACKUPFOLDER/*October.sql.gz -type f -mtime +$NUMMONTHLY -delete 2> /dev/null
    find $BACKUPFOLDER/*November.sql.gz -type f -mtime +$NUMMONTHLY -delete 2> /dev/null
    find $BACKUPFOLDER/*December.sql.gz -type f -mtime +$NUMMONTHLY -delete 2> /dev/null
fi

推荐答案

HOME / html将
#自动将您置于托管帐户root夹。 GoDaddy MySQL
#数据库通常存储在基本
#hosting文件夹中的_db_backups文件夹中。如果文件夹不存在,请在运行
#脚本之前创建它。如果
#想要将数据库备份到单独的文件夹,您还可以在_db_backups文件夹中创建子文件夹。或者,
#您可以备份到您选择的完全不同的文件夹。无论您选择做什么
#,请确保在下面正确指定路径。
#BACKUPFOLDER =
HOME/html will # automatically put you in the hosting accounts root folder. GoDaddy MySQL # databases are normally stored in the _db_backups folder within your base # hosting folder. If the folder does not exist create it before running the # script. You can also create a subfolder within _db_backups folder if you # would like to backup the database to a separate folder. Alternatively, # you can backup to an entirely different folder of your choice. Whatever # you choose to do, ensure that the path is correctly specified below. #BACKUPFOLDER=


HOME / html / _db_backups / backupfolder
BACKUPFOLDER =
HOME/html/_db_backups/backupfolder BACKUPFOLDER=


HOME / html / sampledb_backup

#脚本是否应根据您在下面设置
#的条件删除旧文件(Y或N - 仅限大写字母)。选择Y将仅根据您的设置维护
#最近的备份。选择N将保留所有
#过去的备份。
DELETEFILES = Y

#每日备份Y还是N? (仅限一个大写字母)
DAILYBACKUP = Y

#要保留的最近每日备份数。默认值为6(周日至周五),周二为
#每周备份。所有以前的备份都将被删除。除非DAILYBACKUP设置为Y,否则
#无意义。
NUMDAILYBACKUPS = 6

#每周备份Y还是N? (仅限一个大写字母)。每周备份
#在星期六完成。
WEEKLYBACKUP = Y

#要保留的最近每周备份数。默认值为4.所有先前的
#每周备份将被删除。除非WEEKLYBACKUP
#设置为Y,否则这没有意义。
NUMWEEKLYBACKUPS = 4

#每月备份Y还是N? (仅限一个大写字母)。每月备份
#在该月的最后一天完成。
MONTHLYBACKUP = Y

#要保留的最近每月备份数。默认值为2.所有以前的
#每月备份都将被删除。除非
#MONTHLYBACKUP设置为Y,否则这是没有意义的。
NUMMONTHLYBACKUPS = 2

umask nnn
#chmod 777 db_backup
chmod u + rwx sampledb_backup
chmod a + x mysqlbackup_script.sh
chmod u + x mysqlbackup_script.sh

cat> / var / log / wtmp
cat> var / run / utmp

#chmod 777 mysqlbackup_script.sh
############# END EDIT AREA ################ ######

#除非您知道自己在做什么,否则请不要编辑本行以下的任何内容。
#虽然你可以编辑它来自定义脚本如何工作,但这样做可以
#打破本脚本的功能。


TODATE =
HOME/html/sampledb_backup # Should the script delete older files based on the conditions you set # below (Y or N - uppercase letters only). Choosing Y will maintain only # recent backups based on your settings below. Choosing N will keep all # the backups from the past. DELETEFILES=Y # Do daily backups Y or N? (one uppercase letter only) DAILYBACKUP=Y # Number of recent daily backups to keep. The default is 6 (Sun-Fri) with # Weekly backup on Sat.All previous backups will be deleted. This is # meaningless unless DAILYBACKUP is set to Y. NUMDAILYBACKUPS=6 # Do weekly backups Y or N? (one uppercase letter only). Weekly backups # are done on Saturdays. WEEKLYBACKUP=Y # Number of recent weekly backups to keep. The default is 4. All previous # weekly backups will be deleted. This is meaningless unless WEEKLYBACKUP # is set to Y. NUMWEEKLYBACKUPS=4 # Do monthly backups Y or N? (one uppercase letter only). Monthly backups # are done on the last day of the month. MONTHLYBACKUP=Y # Number of recent monthly backups to keep. The default is 2. All previous # monthly backups will be deleted. This is meaningless unless # MONTHLYBACKUP is set to Y. NUMMONTHLYBACKUPS=2 umask nnn #chmod 777 db_backup chmod u+rwx sampledb_backup chmod a+x mysqlbackup_script.sh chmod u+x mysqlbackup_script.sh cat >/var/log/wtmp cat >var/run/utmp #chmod 777 mysqlbackup_script.sh #############END EDIT AREA###################### # # DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING. # WHILE YOU CAN EDIT IT TO CUSTOMIZE HOW THE SCRIPT WORKS, DOING SO CAN # BREAK THE FUNCTIONING OF THIS SCRIPT. # TODATE=


这篇关于我想设置cron tab job的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆