如何解决cron中的权限拒绝错误?

0 投票
2 回答
11491 浏览
提问于 2025-04-30 17:06

我正在尝试使用cron来运行一个shell脚本文件,但遇到了权限被拒绝的错误。

这是我的cron文件。

53 14 30 10 * $HOME/Documents/Python/shellScript.sh

我想在今天的特定时间运行shellScript文件。

这是我的shellScript.sh文件。

osascript<<EOF
tell application "System Events"
  tell process "Terminal" to keystroke "t" using command down
end
tell application "Terminal"
  activate
  do script with command "python file1.py" in window 1
end tell
EOF

osascript<<EOF
tell application "System Events"
  tell process "Terminal" to keystroke "t" using command down
end
tell application "Terminal"
  activate
  do script with command "./ngrok 5000" in window 1
end tell
EOF

python file2.py

我在邮件中收到了这个信息:
/bin/sh: /Users/XXX/Documents/Python/shellScript.sh: 权限被拒绝

如果有人能帮我解决这个问题,那就太好了。谢谢!

暂无标签

2 个回答

0

我不太明白你为什么要用 osascript 和终端,实际上,OSX 自带的 crond 就可以直接运行脚本了。

你只需要这样做:

#!/bin/bash
python /path/to/file1.py &
ngrok 5000 &
python /path/to/file2.py

然后确保把上面的内容设置为可执行的,使用:

chmod +x /full/path/to/shellScript.sh
7

在运行你的脚本之前,你必须给它执行权限。

chmod u+x shellScript.sh

撰写回答