【问题标题】:How to solve permission denied error in cron? [duplicate]如何解决cron中的权限被拒绝错误? [复制]
【发布时间】:2014-12-26 23:47:30
【问题描述】:

我正在尝试使用 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: 权限被拒绝

如果有人可以帮助我,那就太好了。 谢谢

【问题讨论】:

  • 发布ls -l shellScript.sh 的输出。请将输出编辑到您的帖子中
  • 您必须在执行脚本之前授予执行权限。 chmod u+x shellScript.sh
  • @Hackaholic 是的,它奏效了。如果您可以在答案中发布您的答案,那么我愿意接受。

标签: python shell cron


【解决方案1】:

您必须在执行脚本之前授予执行权限。

chmod u+x shellScript.sh

【讨论】:

    【解决方案2】:

    完全不知道为什么要调用 osascript 和终端 - OSX 的 crond 完全能够自行运行脚本。

    你应该可以这样做:

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

    并确保使上述可执行文件

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 2020-11-08
      • 2010-12-01
      • 1970-01-01
      • 2021-05-24
      • 2015-02-02
      • 2020-04-30
      相关资源
      最近更新 更多