简体   繁体   English

shell 脚本中的 zip 命令无法通过 crontab 工作

[英]zip command in shell script doesn't work via crontab

I have a simple shell script that copies a folder, zips it, then deletes the original folder.我有一个简单的 shell 脚本,它复制一个文件夹,压缩它,然后删除原始文件夹。

#!/bin/bash

today=$(date +%m-%d-%Y)

cp -R /data /perf_backup/
/bin/zip -r data-"$today".zip data
rm -rf data

Works fine when I manually run it.当我手动运行它时工作正常。 The end result is a single zip file as expected.最终结果是预期的单个 zip 文件。 在此处输入图像描述

However when cron job runs, only the initial data directory is there.但是,当 cron 作业运行时,只有初始数据目录存在。 As if everything after the initial folder copy is ignored.好像初始文件夹副本之后的所有内容都被忽略了。

在此处输入图像描述

Crontab is simply crontab 很简单

* * * * 1-5 /opt/backup_data_folder.sh

This is on Oracle Linux Server 7.9 (ie CentOS)这是在 Oracle Linux 服务器 7.9(即 CentOS)上

#!/bin/bash

today=$(date +%m-%d-%Y)

cd /perf_backup/
cp -R /data ./data_backup
zip -r data-"$today".zip data_backup
rm -rf data_backup

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM