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

Clash 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] ^
bash shell-script shell cron command-substitution
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.
 |Â
show 1 more comment
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] ^
bash shell-script shell cron command-substitution
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 callingevalon it is horrible. There are better ways of doing this - particularly when you have a shell such asbashthat 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 fromsbt. 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
 |Â
show 1 more comment
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] ^
bash shell-script shell cron command-substitution
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
bash shell-script shell cron command-substitution
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.
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 callingevalon it is horrible. There are better ways of doing this - particularly when you have a shell such asbashthat 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 fromsbt. 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
 |Â
show 1 more comment
Related: unix.stackexchange.com/questions/444946
â Kusalananda
12 hours ago
2
Putting a command line in a variable and then callingevalon it is horrible. There are better ways of doing this - particularly when you have a shell such asbashthat 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 fromsbt. 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
 |Â
show 1 more comment
active
oldest
votes
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Related: unix.stackexchange.com/questions/444946
â Kusalananda
12 hours ago
2
Putting a command line in a variable and then calling
evalon it is horrible. There are better ways of doing this - particularly when you have a shell such asbashthat 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