在 CentOS 系统中,要在 crontab 中引用外部脚本,请按照以下步骤操作:
chmod 命令为脚本添加可执行权限,例如:chmod +x /path/to/your/script.sh
crontab -e 命令。例如:crontab -e
0 1 * * * /path/to/your/script.sh >> /path/to/your/logfile.log 2>&1
这里,0 1 * * * 表示每天的凌晨 1 点执行任务,>> /path/to/your/logfile.log 2>&1 表示将脚本的输出重定向到日志文件。
注意:确保脚本中的所有路径和依赖项都是绝对路径,因为在 cron 环境中,相对路径可能无法正确解析。