I have a Shell script like below
echo "Hello World"
The script is located in /root/scripts/ folder as test.sh
I also created a cron job like below
0-59 * * * * ./scripts/test.sh
Now the cron job is not printing the content in test.sh every minute.
Let me know whether I have given a wrong directory or I have any other problem in my code.
解决方案
I would
Be explicit wrt. your directory to execute from e.g. /root/scripts/test.sh. I don't know what cron would regard as the current directory
Redirect stdout to a log file e.g. ...test.sh > /tmp/cron.log (you would likely want to redirect stderr at some stage too using 2>&1). Otherwise you're not going to see the output. It gets mailed to the cronjob owner
Make sure you've given execution permission to your bash script (chmod +x /root/scripts/test.sh)
Be explicit which script executable will execute your shell script. It's good practise to have a script invocation at the top e.g. #!/bin/sh or similar
Getting stuff to run under cron is notoriously tricky. Cron jobs run with a massively cut-down environment. It's instructive to print out the environment available to your script (use env) and compare/contrast with what you have available from your interactive shell.