youtube-upload runs from terminal but not cron call

柔情痞子 提交于 2019-12-04 21:22:35

My first guess would be that your default shell is not Bash and that when the script is executed under cron it is be run under a different shell. The reasons I guessing this is that you are experiencing some difference from CLI to CRON is:

  1. I noticed that when run interactively, you are specifying bash via bash up427.sh; and
  2. you don't specify the shell with at the top of your script.

To help us troubleshoot:

  • Can you add your crontab entry to your post?
  • Can you tell us what you see when you run echo $SHELL at the terminal?

UPDATE

Based on your updates, it looks like a mismatched shell maybe not be the root cause. Given the changing error code (from 126 to 127) there has to be more involved. To completely rule out the mismatched shell, can you try the following from the terminal of the target server (logged into the terminal as the same user the crontab is running under) and report back the output:

$ echo $SHELL
$ ps -p $$
$ which bash

Update #2
I would recommend the use of eval. To do so, you would build up up the full command as a string that would be passed to eval. This would be used instead of echo $bash2run >/root/cx.txt. A basic example of the idea is:

my_args='-al'
eval "ls ${my_args}"

If you work up from this basic example, I think you will get it to work.

For small but informative discussion on the use of eval, exec and source, I recommend you read this thread on bash shell: 'exec', 'eval', 'source' - looking for help to understand

In addition, I would recommend running the script in debug mode by adding the -x flag like such:

bash -x up427.sh

UPDATE SOLUTION FOUND! well the solutionin fact deleted some random files so I have taken it off until I figure out why.

I leave this important note from before

ANYTIME YOU USE CRON I cannot emphasize enough the importance of specifying completely the full path of all sh files, files in arguments and any files you want to pipe output too such as >> /mydirectorywhereiwantit/output.txt in full in both your crontab file and your sh files script files.

As I learned cron will look for files and write files in whatever directory it happens to be in while bashing and that can get EXTREMELY confusing if that is a different directory from where you normally type from the terminal. SO FULLY SPECIFY ALL PATHS TO ALL FILES IN BOTH CRONTAB AND IN THE CALLED SH SCRIPT FILES AND IN ARGUMENTS!

Thanks to John Mark Mitchell who so kindly offer so many possible solutions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!