到处搜索,但不能 运行 我自己的示例 bash 带有 crontab 的脚本

Searched everywhere but cannot run my own sample bash script with crontab

#!/usr/bin/env bash
#!/bin/bash 
#!/bin/sh
filename='/home/supersaiyan/sample1.sh'
for i in 1 2 3 4 5
do
  echo "String $i"
  x1+="String"$i
done
echo "#Added string is: $x1" >> $filename
echo "The following string has been added to the file: $x1"

这是我创建的 bash 脚本,它在使用 bash 命令时运行良好。但它在 crontab 中不起作用。

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
5 * * * * echo '#tanginamo cron tester' >> /home/supersaiyan/samplerz.sh
* * * * * /bin/bash /home/supersaiyan/sample1.sh

这是我在 crontab 中输入的内容。第一行仅用于测试并且工作正常所以我真的不知道为什么第二行不起作用。

编辑:尝试删除 SHELL 和 PATH 行无济于事 .sh 文件已被修改为可执行文件

您的输出应该与您的实际脚本文件不同。

您需要更改:

filename='/home/supersaiyan/sample1.sh'

至:

filename='/home/supersaiyan/sample1.out'

...和 ​​运行 脚本。 您可能想查看第 10 行左右之后的内容。 享受! :)