如何制作bash脚本来自动从github添加和下载文件



我在linux服务器上有一个克隆的目录。已配置键控访问。在服务器上经过一些处理后,在输出端,我得到了需要添加到git中的csv文件。我还需要在服务器上接收git本身已更改的文件(这些文件可以是新添加的文件,也可以是代码中的一些更改(。添加过程每天都在发生,所以我想自动化它。在其中一个网站上,我找到了一个适合我的例子。两个脚本可以添加和克隆对服务器的更改。启动自动化通过crontab实现。

代码文件:

#!/bin/bash
# Go to the GIT category
cd '/home/user/www/'
# Submitting changes to the main branch
git checkout main
git add -A
git commit -m "update main"
git push

而且。。。

#!/bin/bash
# Go to the GIT category
cd '/home/user/www/'
# Loading data from the main branch
git checkout main
git pull

但我在输出中出现了以下错误,可能是什么问题?

Cronlog:

/home/user/RFFI-V/Work/start_git_download.sh: line 3: cd: too many arguments
/home/user/RFFI-V/Work/start_git_push.sh: line 3: cd: too many arguments
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

手动运行每个命令,查看是否收到任何问题。

如果你没有收到任何问题,那么bash脚本是否在crontab的正确文件夹中,并且默认情况下该脚本将以root身份运行,如果你想以不同的用户身份运行该脚本,下面显示了在crontab中设置脚本以不同用户身份运行的示例语法,

1 2 3 4 5 USERNAME /path/to/script.sh

最新更新