I have scheduled a job in crontab to run on every last Friday of the month, it never runs and gives me error as
/bin/sh: line 0: [: missing `]'
However, it works when I run the shell script manually.
why am I getting this error?
Related
The below code is being used to trigger a shell command using Jenkins file.
sh """
val=\$(echo ${val} | sed 's/[^a-zA-Z0-9]//g')
echo ${val}
"""
The below error reflects as part of the code :
/home/me/#tmp/abcd/script.sh: command substitution: line 4: syntax error near unexpected token `('
Any solution to the same ? Thanks in advance!
I have the following entry in my crontab:
0,30 7-18 * * 1-5 cd /path/to/scrapers && scrapy crawl funny_quotes &>> $(date "+/home/foobar/logs/\%Y\%m\%d.funny.log"
This entry is supposed to run every half hour, on weekdays and append the output to the log file each time it's run. I have tested the syntax online, using this handy tool, and the syntax is correct.
However, the job doesn't get run. What's worse, the log file is created (but has no contents - file size 0), so I have no diagnostic information to go by.
The command cd /path/to/scrapers && scrapy crawl funny_quotes runs perfectly when I type it at the command, and there is copious amounts of information output to the console, from scrapy.
Why does the cronjob fail to run sccessfully - and why is nothing being piped to the log file?
Check your cron logs
grep CRON /var/log/syslog
I am sure you are getting error something like scrapy - command not found or something similar.
To fix it, do this
Enter and copy the output of echo $PATH from shell.
And then open crontab -e
At the very top of file, write PATH=YOUR_COPIED_CONTENTS
And that should work.
This question already has answers here:
Getting "command not found" error in bash script
(6 answers)
CronJob not running
(19 answers)
Closed 2 years ago.
When running the below command,
* * * * * /home/path1/path2/myScript.sh >>/home/path1/path2/Logs/output.txt 2>&1
I got the following error
bash: apache-solr-1.4.2-dev.zip: command not found
// if we delete this folder/zip from its location it goes to the below error.
// It is just taking some folder names and throwing errors
bash: apache-solr-1.4.2.zip: command not found
bash: apache-solr-1.4.zip: command not found
bash: someFolder.zip: command not found
bash: someFolder2.zip: command not found
bash: someFolder3.zip: command not found
myScript.sh contains:
echo "this is my script"
I can't understand the relation between Solr and Cron job. Please help me out.
To configure cron, you'll have to edit the users cronfile. You can usually do this by doing crontab -e logged in as the actual users. This will launch $EDITOR and let you edit the current cron file.
You'll need to enter the cron configuration into this file, and not just pasting it on the command line as you're doing.
* * * * * /home/path1/path2/myScript.sh >>/home/path1/path2/Logs/output.txt 2>&1
The error messages you're getting is from the *s being expanded into the actual contents of the directory you're inside.
I've run the cron job command directly instead of creating/editing the cron job. After ruuning the command using
crontab -e
it worked fine.
Thanks for replies.
The cron job does nothing else than to start myScript.sh at certain times. I think you get the error message because you are referring to that apache-solr-1.4.2-dev.zip or to something that the apache-solr-1.4.2-dev.zip does from within the script myScript.sh.
So, the error message has to do with the script and not with the cron job. To find the cause for the error, you will have to fix the script.
I have cron scheduler for jar execution which is internally running ruby script, when I run the cron command on command line it works fine, and gives no error. But when I execute same command through cron then it is giving status code 127. Considering the issue of environment variable(PATH) I tried to add . ~/.bash_profile; in cron command and run it again but it is giving me same status.
Below is the details of cron and ruby command:
Cron Command:
30 5 * * * . ~/.bash_profile; java -jar /usr/car_price/bin/carUtils.jar
Ruby command called by jar:
ruby /usr/car_price/bin/apiclient.rb > /usr/car_price/rubyLog/2015-01-07_05:30:04_TPA.log
Please help me to resolve the issue.
I am configuring Cron to backup my sql automatically. However I think that Cron has some issues and it's not working well.
This is the command I am running:
mysqldump --opt -Q -uhereisthename -p'hereisthepasswordwithstrangecharactersthatmustbeescaped' databasename | gzip > /home2/username/backups/backupnamefolder/backupdbwebsitename.`date +"%Y-%m-%d"`.gz
When I run it via SSH it works fine and generates the backup.
However if I run it via Cron, I get the following error:
/bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file
Anybody can suggest what's wrong?
Cron treats % as a special character (meaning "new line", hence the references to lines 0 and 1 in the error message). You need to escape it:
date "+\%Y-\%m-\%d"
By the way, the posix $( ) syntax is generally better than backticks - it allows nested commands.