I have a script of the following format:
#!/bin/bash
cd /abc/def/user1/test
export NIMBUS_ENV_FILE=/abc/def/user1/test/nimbus_env
main/vdnet -c yaml/config.yaml -t ABC...*
my script executes perfectly when run from the shell.I want to execute this script daily and so i have set a cron job for the same by editing crontab -e as :
PATH=/usr/bin:/usr/sbin:.
00 12 * * * /home/test.sh > /home/testCronLog.log 2>&1
Hoever, the cron job is run but it does not run the script as expected and gives following errors:
main/vdnet: line 2: readlink: command not found
dirname: missing operand
Try 'dirname --help' for more information.
main/vdnet: line 3: /../main/environment: No such file or directory
main/vdnet: line 8: /../scripts/nimbus/setup: No such file or
directory
main/vdnet: line 14: /../main/vdNet.pl: No such file or directory
I do not get these errors when I manually execute the script and am not able to figure out whats wrong.The owner of the script is same as the crontab user.
Please Help!!!
The issue is now resolved.
I added the path to the script before running my command main/vdnet :
export PATH=...
Thanks
when you use some command or something, or your script, its always better to give full path
so give full path of main/vdnet in your script
try changing the line which calls vdnet line in test.sh to:
main/vdnet -c /abc/def/user1/testyaml/config.yaml -t ABC...*
Your problem I think is that although test.sh runs perfectly from crontab, main/vdnet does not, and that is because the reference you have supplied it as the argument to the -c option needs the full path.
Related
Want to schedule a sh-script but crontab does not execute it.
However, the script is executable manually without any issues.
"crontab -l"-Output:
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
48 16 * * 1,2,3,4,5 /home/pentaho_admin/pdi/schedule.sh
the shell script included a command with the following command in the 2nd line:
./kitchen.sh
1st line:
alias xyz="cd..." (leads to the folder of kitchen.sh)
That first line apparently cannot be interpreted by crontab.
Solution:
I've added the full path to kitchen.sh
Is there any more sexy solution?
I get the following error (error.message) when I run the following shell script (myscript.sh).
myscript.sh
#!/bin/bash
cd /path/to/ && node app.js
error.message
/path/to/myscript.sh: line 1: #!/bin/bash: No such file or directory
/path/to/myscript.sh: line 2: node: command not found
I have already run the following command line instructions.
command-line
chmod u+x /path/to/myscript.sh
chmod u+x /path/to/app.js
Also, I know I have node installed because when I run:
node -v
I get back:
v5.5.1
I execute myscript.sh via the following AppleScript:
MyApp.applescript
do shell script "bash /path/to/myscript.sh"
Also: which bash returns /bin/bash
What could be causing this error and how can I fix it?
I fixed the first error:
/path/to/myscript.sh: line 1: #!/bin/bash: No such file or directory
By copying a working .sh file I had on my machine and copy/pasting the code from the old file to the new file.
I'm guessing somehow there was a filetype issue or discrepancy despite the fact that I used a .sh extension in the file name.
In the future, I will double check the file type in my Finder utility (Max OS X v10.10.1).
However, I am still seeing the second error:
/path/to/myscript.sh: line 2: node: command not found
Credit goes to #HeadCode and #mh-cbon for helping me figure this out with their comments.
I solved the second problem by running:
myshell.sh
#!/bin/bash
path/to/node path/to/app.js
where path/to/node was found by running
command-line
which node
and path/to/app.js is the actual file tree path to app.js. (In other words, different from path/to/node.)
I have the following test.sh file in /home/me folder
#!/bin/sh
_now=$(date +"%Y_%m_%d")
_file="/home/me/$_now.txt"
speedtest-cli --simple > $_file
Where speedtest-cli is a python script that gives internet up and dll speed infos : https://github.com/sivel/speedtest-cli.
Calling test.sh from /home/me works very good: I get my yyy_mm_dd.txt output with all infos (dll speed up speed, etc.).
But when I try to call the test.sh from a crontab I get a empty yyy_mm_dd.txt file (nothing inside).
Inside crontab-e
20 20 * * * /home/me/test.sh
Did I do something wrong?
I suspect a PATH problem, so
pick one of :
add PATH=/usr/local/bin:/bin:/usr/bin in the top of your script
add in the top of crontab -e : PATH=/usr/local/bin:/bin:/usr/bin on his own line
source ~/.bashrc in the top of your script
add full path to each commands in your script
Your PATH is probably different for your interactive shell than the context your cronjob runs in, so you should specify the full path of speedtest-cli in your crontab entry.
I have the following command inside a shell script at /home/ubuntu/wget_my_url.sh
the conent of ping_my_url are as follows -
wget -O - -q -t 1 http://www.someurl.com/baseurl/
There is no line break in the above file.
I did chmod +x wget_my_url.sh
Inside my /etc/crontab I have the following - */1 * * * * /home/ubuntu/wget_my_url.sh
There is a line break after the above line inside the crontab file.
When I run manually wget_my_url.sh, I get the desired result, but inside a cron tab, it does not run.
Please let me know, whats wrong with it.
Thanks.
What do you mean with the "desired result" ?
Your script just print choses on the screen (the standard out), but, the scripts on the crontab doesn't have a screen to print.
So, I think that it's running normally but you can't realize cause you don't see the script's output.
Instead of just print, why don't you print on a file making something like
wget -O - -q -t 1 http://www.someurl.com/baseurl/ > /home/ubuntu/OUT_FILE
?
Like that you'll be able to check if it works just checking if the file /home/ubuntu/OUT_FILE exists and you'll be able to use the script's output too.
I wrote a linux command and it runs perfectly in command line:
/bin/netstat -an | grep '3306' | sed 's/.*/[MYSQLMON]&/' > /home/bbWifiExt/logs/WIFIMonitor.log
however when I copy this code to .sh and run the .sh file i got:
No such file or directory
Can anyone tell me why? Many thanks.
You must either call it as
sh mycommand.sh
or make your shell script executable. Insert #! /bin/sh or #! /bin/bash as the first line and
chmod +x mycommand.sh
before calling
mycommand.sh
for my situation (rename and copied file from windows to linux) the solution was :
dos2unix script.sh
If the first line of the script something like
#!/bin/sh
and the execute bit set i.e.
chmod +x script.sh