How to get linux shell script command containing quote working in crontab?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I see an Issue, where shell script command/script works fine when ran through command line or shell script but fails when triggered through crontab.
Following are details of the command



Command run through command prompt:



$ sbt "gatling:testOnly someTest"


command wrapped in shell script:



$ more runTest2.sh 
#!/usr/bin/env bash
set -x
cmdline='sbt "gatling:testOnly someTest"'
echo " commandToRun " $cmdline
eval $cmdline


Both shell script run and direct command line run works fine



crontab -l
02 22 * * * /home/ranjesh_viswa/someproject/test/performance/runTest2.sh >> /home/someuser/someproject/test/performance/testLog.log 2>&1


Error show when ran through crontab:



+ cmdline='sbt "gatling:testOnly someTest"'
+ echo ' commandToRun ' sbt '"gatling:testOnly' 'someTest"'
commandToRun sbt "gatling:testOnly someTest"
+ eval sbt '"gatling:testOnly' 'someTest"'
++ sbt 'gatling:testOnly someTest'
[info] Loading project definition from /home/someuser/project
[info] Set current project to someuser (in build file:/home/someuser/)
[error] Expected key
[error] Expected '::'
[error] Expected end of input.
[error] No such setting/task
[error] gatling:testOnly someTest
[error] ^









share|improve this question









New contributor




mohan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Related: unix.stackexchange.com/questions/444946
    – Kusalananda
    12 hours ago






  • 2




    Putting a command line in a variable and then calling eval on it is horrible. There are better ways of doing this - particularly when you have a shell such as bash that understands arrays. But in your example I'm not sure why you'd want this level of indirection at all - why not just run the command directly?
    – roaima
    12 hours ago










  • But the original question remains, why it works fine when same shells script run as './runTest2.sh' but fails when triggered through crontab. Both are using same bash
    – mohan
    12 hours ago










  • I had modified script to use array as mentioned by @Kusalananda The new script is ``` $ more runTest2.sh #!/usr/bin/env bash set -x cmdline='sbt "gatling:testOnly someTest"' mycmd=(sbt "gatling:testOnly someTest") echo " commandToRun " $mycmd "$mycmd[@]"``` But stilll same issue, runs fine in shell script, but fails when triggered through crontab
    – mohan
    11 hours ago







  • 1




    This is not a shell/script problem. The error is coming from sbt. The fact that it runs on the commandline but not in cron indicates there's something missing in the environment: see Why is my crontab not working and how can I troubleshoot it
    – glenn jackman
    7 hours ago















up vote
1
down vote

favorite












I see an Issue, where shell script command/script works fine when ran through command line or shell script but fails when triggered through crontab.
Following are details of the command



Command run through command prompt:



$ sbt "gatling:testOnly someTest"


command wrapped in shell script:



$ more runTest2.sh 
#!/usr/bin/env bash
set -x
cmdline='sbt "gatling:testOnly someTest"'
echo " commandToRun " $cmdline
eval $cmdline


Both shell script run and direct command line run works fine



crontab -l
02 22 * * * /home/ranjesh_viswa/someproject/test/performance/runTest2.sh >> /home/someuser/someproject/test/performance/testLog.log 2>&1


Error show when ran through crontab:



+ cmdline='sbt "gatling:testOnly someTest"'
+ echo ' commandToRun ' sbt '"gatling:testOnly' 'someTest"'
commandToRun sbt "gatling:testOnly someTest"
+ eval sbt '"gatling:testOnly' 'someTest"'
++ sbt 'gatling:testOnly someTest'
[info] Loading project definition from /home/someuser/project
[info] Set current project to someuser (in build file:/home/someuser/)
[error] Expected key
[error] Expected '::'
[error] Expected end of input.
[error] No such setting/task
[error] gatling:testOnly someTest
[error] ^









share|improve this question









New contributor




mohan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Related: unix.stackexchange.com/questions/444946
    – Kusalananda
    12 hours ago






  • 2




    Putting a command line in a variable and then calling eval on it is horrible. There are better ways of doing this - particularly when you have a shell such as bash that understands arrays. But in your example I'm not sure why you'd want this level of indirection at all - why not just run the command directly?
    – roaima
    12 hours ago










  • But the original question remains, why it works fine when same shells script run as './runTest2.sh' but fails when triggered through crontab. Both are using same bash
    – mohan
    12 hours ago










  • I had modified script to use array as mentioned by @Kusalananda The new script is ``` $ more runTest2.sh #!/usr/bin/env bash set -x cmdline='sbt "gatling:testOnly someTest"' mycmd=(sbt "gatling:testOnly someTest") echo " commandToRun " $mycmd "$mycmd[@]"``` But stilll same issue, runs fine in shell script, but fails when triggered through crontab
    – mohan
    11 hours ago







  • 1




    This is not a shell/script problem. The error is coming from sbt. The fact that it runs on the commandline but not in cron indicates there's something missing in the environment: see Why is my crontab not working and how can I troubleshoot it
    – glenn jackman
    7 hours ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I see an Issue, where shell script command/script works fine when ran through command line or shell script but fails when triggered through crontab.
Following are details of the command



Command run through command prompt:



$ sbt "gatling:testOnly someTest"


command wrapped in shell script:



$ more runTest2.sh 
#!/usr/bin/env bash
set -x
cmdline='sbt "gatling:testOnly someTest"'
echo " commandToRun " $cmdline
eval $cmdline


Both shell script run and direct command line run works fine



crontab -l
02 22 * * * /home/ranjesh_viswa/someproject/test/performance/runTest2.sh >> /home/someuser/someproject/test/performance/testLog.log 2>&1


Error show when ran through crontab:



+ cmdline='sbt "gatling:testOnly someTest"'
+ echo ' commandToRun ' sbt '"gatling:testOnly' 'someTest"'
commandToRun sbt "gatling:testOnly someTest"
+ eval sbt '"gatling:testOnly' 'someTest"'
++ sbt 'gatling:testOnly someTest'
[info] Loading project definition from /home/someuser/project
[info] Set current project to someuser (in build file:/home/someuser/)
[error] Expected key
[error] Expected '::'
[error] Expected end of input.
[error] No such setting/task
[error] gatling:testOnly someTest
[error] ^









share|improve this question









New contributor




mohan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I see an Issue, where shell script command/script works fine when ran through command line or shell script but fails when triggered through crontab.
Following are details of the command



Command run through command prompt:



$ sbt "gatling:testOnly someTest"


command wrapped in shell script:



$ more runTest2.sh 
#!/usr/bin/env bash
set -x
cmdline='sbt "gatling:testOnly someTest"'
echo " commandToRun " $cmdline
eval $cmdline


Both shell script run and direct command line run works fine



crontab -l
02 22 * * * /home/ranjesh_viswa/someproject/test/performance/runTest2.sh >> /home/someuser/someproject/test/performance/testLog.log 2>&1


Error show when ran through crontab:



+ cmdline='sbt "gatling:testOnly someTest"'
+ echo ' commandToRun ' sbt '"gatling:testOnly' 'someTest"'
commandToRun sbt "gatling:testOnly someTest"
+ eval sbt '"gatling:testOnly' 'someTest"'
++ sbt 'gatling:testOnly someTest'
[info] Loading project definition from /home/someuser/project
[info] Set current project to someuser (in build file:/home/someuser/)
[error] Expected key
[error] Expected '::'
[error] Expected end of input.
[error] No such setting/task
[error] gatling:testOnly someTest
[error] ^






bash shell-script shell cron command-substitution






share|improve this question









New contributor




mohan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




mohan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 12 hours ago









Ipor Sircer

9,4231920




9,4231920






New contributor




mohan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 12 hours ago









mohan

61




61




New contributor




mohan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





mohan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






mohan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • Related: unix.stackexchange.com/questions/444946
    – Kusalananda
    12 hours ago






  • 2




    Putting a command line in a variable and then calling eval on it is horrible. There are better ways of doing this - particularly when you have a shell such as bash that understands arrays. But in your example I'm not sure why you'd want this level of indirection at all - why not just run the command directly?
    – roaima
    12 hours ago










  • But the original question remains, why it works fine when same shells script run as './runTest2.sh' but fails when triggered through crontab. Both are using same bash
    – mohan
    12 hours ago










  • I had modified script to use array as mentioned by @Kusalananda The new script is ``` $ more runTest2.sh #!/usr/bin/env bash set -x cmdline='sbt "gatling:testOnly someTest"' mycmd=(sbt "gatling:testOnly someTest") echo " commandToRun " $mycmd "$mycmd[@]"``` But stilll same issue, runs fine in shell script, but fails when triggered through crontab
    – mohan
    11 hours ago







  • 1




    This is not a shell/script problem. The error is coming from sbt. The fact that it runs on the commandline but not in cron indicates there's something missing in the environment: see Why is my crontab not working and how can I troubleshoot it
    – glenn jackman
    7 hours ago

















  • Related: unix.stackexchange.com/questions/444946
    – Kusalananda
    12 hours ago






  • 2




    Putting a command line in a variable and then calling eval on it is horrible. There are better ways of doing this - particularly when you have a shell such as bash that understands arrays. But in your example I'm not sure why you'd want this level of indirection at all - why not just run the command directly?
    – roaima
    12 hours ago










  • But the original question remains, why it works fine when same shells script run as './runTest2.sh' but fails when triggered through crontab. Both are using same bash
    – mohan
    12 hours ago










  • I had modified script to use array as mentioned by @Kusalananda The new script is ``` $ more runTest2.sh #!/usr/bin/env bash set -x cmdline='sbt "gatling:testOnly someTest"' mycmd=(sbt "gatling:testOnly someTest") echo " commandToRun " $mycmd "$mycmd[@]"``` But stilll same issue, runs fine in shell script, but fails when triggered through crontab
    – mohan
    11 hours ago







  • 1




    This is not a shell/script problem. The error is coming from sbt. The fact that it runs on the commandline but not in cron indicates there's something missing in the environment: see Why is my crontab not working and how can I troubleshoot it
    – glenn jackman
    7 hours ago
















Related: unix.stackexchange.com/questions/444946
– Kusalananda
12 hours ago




Related: unix.stackexchange.com/questions/444946
– Kusalananda
12 hours ago




2




2




Putting a command line in a variable and then calling eval on it is horrible. There are better ways of doing this - particularly when you have a shell such as bash that understands arrays. But in your example I'm not sure why you'd want this level of indirection at all - why not just run the command directly?
– roaima
12 hours ago




Putting a command line in a variable and then calling eval on it is horrible. There are better ways of doing this - particularly when you have a shell such as bash that understands arrays. But in your example I'm not sure why you'd want this level of indirection at all - why not just run the command directly?
– roaima
12 hours ago












But the original question remains, why it works fine when same shells script run as './runTest2.sh' but fails when triggered through crontab. Both are using same bash
– mohan
12 hours ago




But the original question remains, why it works fine when same shells script run as './runTest2.sh' but fails when triggered through crontab. Both are using same bash
– mohan
12 hours ago












I had modified script to use array as mentioned by @Kusalananda The new script is ``` $ more runTest2.sh #!/usr/bin/env bash set -x cmdline='sbt "gatling:testOnly someTest"' mycmd=(sbt "gatling:testOnly someTest") echo " commandToRun " $mycmd "$mycmd[@]"``` But stilll same issue, runs fine in shell script, but fails when triggered through crontab
– mohan
11 hours ago





I had modified script to use array as mentioned by @Kusalananda The new script is ``` $ more runTest2.sh #!/usr/bin/env bash set -x cmdline='sbt "gatling:testOnly someTest"' mycmd=(sbt "gatling:testOnly someTest") echo " commandToRun " $mycmd "$mycmd[@]"``` But stilll same issue, runs fine in shell script, but fails when triggered through crontab
– mohan
11 hours ago





1




1




This is not a shell/script problem. The error is coming from sbt. The fact that it runs on the commandline but not in cron indicates there's something missing in the environment: see Why is my crontab not working and how can I troubleshoot it
– glenn jackman
7 hours ago





This is not a shell/script problem. The error is coming from sbt. The fact that it runs on the commandline but not in cron indicates there's something missing in the environment: see Why is my crontab not working and how can I troubleshoot it
– glenn jackman
7 hours ago
















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






mohan is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474209%2fhow-to-get-linux-shell-script-command-containing-quote-working-in-crontab%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








mohan is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















mohan is a new contributor. Be nice, and check out our Code of Conduct.












mohan is a new contributor. Be nice, and check out our Code of Conduct.











mohan is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474209%2fhow-to-get-linux-shell-script-command-containing-quote-working-in-crontab%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)