curl bash script works fine in shell but not work in cronjob Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Come Celebrate our 10 Year Anniversary!Bash script works from prompt but not from cronbash shell command runs fine at command prompt, but not in my .sh script?Why doesn't this command work as a cronjob, while it works perfectly when typed in a shell?expect script works fine standalone not from bash scriptExecuting script remotely with “curl | bash” feedbackUbuntu 10.04 cronjob with curl dosen't workCURL & SSL failing on a specific sitebash scripts work fine when I run it from command line but not from cronshell script not working in cronjobCentOS 7: curl and wget not working
Can the Great Weapon Master feat's damage bonus and accuracy penalty apply to attacks from the Spiritual Weapon spell?
How come Sam didn't become Lord of Horn Hill?
Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?
Illegal assignment from sObject to Id
Maximum summed subsequences with non-adjacent items
Chinese Seal on silk painting - what does it mean?
How do living politicians protect their readily obtainable signatures from misuse?
What is the difference between globalisation and imperialism?
What would you call this weird metallic apparatus that allows you to lift people?
Why do we bend a book to keep it straight?
When a candle burns, why does the top of wick glow if bottom of flame is hottest?
Is it possible for SQL statements to execute concurrently within a single session in SQL Server?
Performance gap between vector<bool> and array
Using audio cues to encourage good posture
Should I follow up with an employee I believe overracted to a mistake I made?
What was the first language to use conditional keywords?
Sum letters are not two different
How were pictures turned from film to a big picture in a picture frame before digital scanning?
As a beginner, should I get a Squier Strat with a SSS config or a HSS?
Do any jurisdictions seriously consider reclassifying social media websites as publishers?
If Windows 7 doesn't support WSL, then what does Linux subsystem option mean?
Morning, Afternoon, Night Kanji
Why is the AVR GCC compiler using a full `CALL` even though I have set the `-mshort-calls` flag?
How does the math work when buying airline miles?
curl bash script works fine in shell but not work in cronjob
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Come Celebrate our 10 Year Anniversary!Bash script works from prompt but not from cronbash shell command runs fine at command prompt, but not in my .sh script?Why doesn't this command work as a cronjob, while it works perfectly when typed in a shell?expect script works fine standalone not from bash scriptExecuting script remotely with “curl | bash” feedbackUbuntu 10.04 cronjob with curl dosen't workCURL & SSL failing on a specific sitebash scripts work fine when I run it from command line but not from cronshell script not working in cronjobCentOS 7: curl and wget not working
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a script using curl to do the job and set into crontabs.
Things were fine on redhat 7.5+ or CentOS 7.
But in redhat 7.2, the script turned into a junk and never output a thing from the curl results.
OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
[[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content-Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp
cat /tmp/curl.tmp >> $OUTPUT
echo >> $OUTPUT
Result: the script runs normally under shell, but does not run in cronjob. The /tmp/curl.tmp is generated but the $OUTPUT /tmp/apm.log is size 0.
After trial tests overnight, I found a potential solution.
OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
[[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content- Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp
while :
do
[ -f /tmp/curl.tmp ] && break
sleep 1
done**
cat /tmp/curl.tmp >> $OUTPUT
echo >> $OUTPUT
I added a while loop after curl to wait for the determination of the output file, following steps are not processed until the file is found. The script then can run normally as expected in cronjob.
It appears that the cron environment does not wait for the curl to finish it's task. So my question is, how can that be fixed ?
Red Hat Enterprise Linux Server 7.2 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.16.2.3 Basic ECC
zlib/1.2.7 libidn/1.28 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3
pop3s rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL lib
bash cron curl
New contributor
|
show 1 more comment
I have a script using curl to do the job and set into crontabs.
Things were fine on redhat 7.5+ or CentOS 7.
But in redhat 7.2, the script turned into a junk and never output a thing from the curl results.
OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
[[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content-Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp
cat /tmp/curl.tmp >> $OUTPUT
echo >> $OUTPUT
Result: the script runs normally under shell, but does not run in cronjob. The /tmp/curl.tmp is generated but the $OUTPUT /tmp/apm.log is size 0.
After trial tests overnight, I found a potential solution.
OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
[[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content- Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp
while :
do
[ -f /tmp/curl.tmp ] && break
sleep 1
done**
cat /tmp/curl.tmp >> $OUTPUT
echo >> $OUTPUT
I added a while loop after curl to wait for the determination of the output file, following steps are not processed until the file is found. The script then can run normally as expected in cronjob.
It appears that the cron environment does not wait for the curl to finish it's task. So my question is, how can that be fixed ?
Red Hat Enterprise Linux Server 7.2 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.16.2.3 Basic ECC
zlib/1.2.7 libidn/1.28 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3
pop3s rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL lib
bash cron curl
New contributor
1
There is a typo in your script as shown above. It appears a space betweenContent-
andType
in thecurl
command. Check your original script.
– Michael Hampton♦
Apr 13 at 0:49
typo fixed. it's not the original cause.
– Yeats Raw
Apr 13 at 4:23
Update the system.
– Michael Hampton♦
Apr 13 at 4:30
In the second line your are usingtmp/curl.tmp
where a/
is missing, so the logfile doesn't get deleted. Instead of the first two lines you could simply writeOUTPUT=/tmp/apm.log; rm -f $OUTPUT /curl.tmp; touch $OUTPUT
.
– Freddy
Apr 13 at 5:20
Why do you use two files/tmp/apm.log
and/tmp/curl.tmp
instead of one?
– Freddy
Apr 13 at 5:26
|
show 1 more comment
I have a script using curl to do the job and set into crontabs.
Things were fine on redhat 7.5+ or CentOS 7.
But in redhat 7.2, the script turned into a junk and never output a thing from the curl results.
OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
[[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content-Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp
cat /tmp/curl.tmp >> $OUTPUT
echo >> $OUTPUT
Result: the script runs normally under shell, but does not run in cronjob. The /tmp/curl.tmp is generated but the $OUTPUT /tmp/apm.log is size 0.
After trial tests overnight, I found a potential solution.
OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
[[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content- Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp
while :
do
[ -f /tmp/curl.tmp ] && break
sleep 1
done**
cat /tmp/curl.tmp >> $OUTPUT
echo >> $OUTPUT
I added a while loop after curl to wait for the determination of the output file, following steps are not processed until the file is found. The script then can run normally as expected in cronjob.
It appears that the cron environment does not wait for the curl to finish it's task. So my question is, how can that be fixed ?
Red Hat Enterprise Linux Server 7.2 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.16.2.3 Basic ECC
zlib/1.2.7 libidn/1.28 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3
pop3s rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL lib
bash cron curl
New contributor
I have a script using curl to do the job and set into crontabs.
Things were fine on redhat 7.5+ or CentOS 7.
But in redhat 7.2, the script turned into a junk and never output a thing from the curl results.
OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
[[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content-Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp
cat /tmp/curl.tmp >> $OUTPUT
echo >> $OUTPUT
Result: the script runs normally under shell, but does not run in cronjob. The /tmp/curl.tmp is generated but the $OUTPUT /tmp/apm.log is size 0.
After trial tests overnight, I found a potential solution.
OUTPUT=/tmp/apm.log; touch $OUTPUT && truncate -s 0 $OUTPUT
[[ -f tmp/curl.tmp ]] && rm -f /tmp/curl.tmp
curl -s --connect-timeout 2 -XGET "http://www.google.com" -H Content- Type:application/json -d @/tmp/apm.json -o /tmp/curl.tmp
while :
do
[ -f /tmp/curl.tmp ] && break
sleep 1
done**
cat /tmp/curl.tmp >> $OUTPUT
echo >> $OUTPUT
I added a while loop after curl to wait for the determination of the output file, following steps are not processed until the file is found. The script then can run normally as expected in cronjob.
It appears that the cron environment does not wait for the curl to finish it's task. So my question is, how can that be fixed ?
Red Hat Enterprise Linux Server 7.2 (Maipo)
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.16.2.3 Basic ECC
zlib/1.2.7 libidn/1.28 libssh2/1.4.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3
pop3s rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL lib
bash cron curl
bash cron curl
New contributor
New contributor
edited Apr 13 at 4:23
Yeats Raw
New contributor
asked Apr 12 at 23:39
Yeats RawYeats Raw
11
11
New contributor
New contributor
1
There is a typo in your script as shown above. It appears a space betweenContent-
andType
in thecurl
command. Check your original script.
– Michael Hampton♦
Apr 13 at 0:49
typo fixed. it's not the original cause.
– Yeats Raw
Apr 13 at 4:23
Update the system.
– Michael Hampton♦
Apr 13 at 4:30
In the second line your are usingtmp/curl.tmp
where a/
is missing, so the logfile doesn't get deleted. Instead of the first two lines you could simply writeOUTPUT=/tmp/apm.log; rm -f $OUTPUT /curl.tmp; touch $OUTPUT
.
– Freddy
Apr 13 at 5:20
Why do you use two files/tmp/apm.log
and/tmp/curl.tmp
instead of one?
– Freddy
Apr 13 at 5:26
|
show 1 more comment
1
There is a typo in your script as shown above. It appears a space betweenContent-
andType
in thecurl
command. Check your original script.
– Michael Hampton♦
Apr 13 at 0:49
typo fixed. it's not the original cause.
– Yeats Raw
Apr 13 at 4:23
Update the system.
– Michael Hampton♦
Apr 13 at 4:30
In the second line your are usingtmp/curl.tmp
where a/
is missing, so the logfile doesn't get deleted. Instead of the first two lines you could simply writeOUTPUT=/tmp/apm.log; rm -f $OUTPUT /curl.tmp; touch $OUTPUT
.
– Freddy
Apr 13 at 5:20
Why do you use two files/tmp/apm.log
and/tmp/curl.tmp
instead of one?
– Freddy
Apr 13 at 5:26
1
1
There is a typo in your script as shown above. It appears a space between
Content-
and Type
in the curl
command. Check your original script.– Michael Hampton♦
Apr 13 at 0:49
There is a typo in your script as shown above. It appears a space between
Content-
and Type
in the curl
command. Check your original script.– Michael Hampton♦
Apr 13 at 0:49
typo fixed. it's not the original cause.
– Yeats Raw
Apr 13 at 4:23
typo fixed. it's not the original cause.
– Yeats Raw
Apr 13 at 4:23
Update the system.
– Michael Hampton♦
Apr 13 at 4:30
Update the system.
– Michael Hampton♦
Apr 13 at 4:30
In the second line your are using
tmp/curl.tmp
where a /
is missing, so the logfile doesn't get deleted. Instead of the first two lines you could simply write OUTPUT=/tmp/apm.log; rm -f $OUTPUT /curl.tmp; touch $OUTPUT
.– Freddy
Apr 13 at 5:20
In the second line your are using
tmp/curl.tmp
where a /
is missing, so the logfile doesn't get deleted. Instead of the first two lines you could simply write OUTPUT=/tmp/apm.log; rm -f $OUTPUT /curl.tmp; touch $OUTPUT
.– Freddy
Apr 13 at 5:20
Why do you use two files
/tmp/apm.log
and /tmp/curl.tmp
instead of one?– Freddy
Apr 13 at 5:26
Why do you use two files
/tmp/apm.log
and /tmp/curl.tmp
instead of one?– Freddy
Apr 13 at 5:26
|
show 1 more comment
1 Answer
1
active
oldest
votes
I think it is environment issue, crontab uses /bin/sh as a default shell, sh does not understand double brackets, it is also possiblle that in newer versions of centos /bin/sh replaced by symlink to /bin/bash
Try adding this line in the begining your crontab file:
SHELL=/bin/bash
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
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',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Yeats Raw 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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f962873%2fcurl-bash-script-works-fine-in-shell-but-not-work-in-cronjob%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think it is environment issue, crontab uses /bin/sh as a default shell, sh does not understand double brackets, it is also possiblle that in newer versions of centos /bin/sh replaced by symlink to /bin/bash
Try adding this line in the begining your crontab file:
SHELL=/bin/bash
add a comment |
I think it is environment issue, crontab uses /bin/sh as a default shell, sh does not understand double brackets, it is also possiblle that in newer versions of centos /bin/sh replaced by symlink to /bin/bash
Try adding this line in the begining your crontab file:
SHELL=/bin/bash
add a comment |
I think it is environment issue, crontab uses /bin/sh as a default shell, sh does not understand double brackets, it is also possiblle that in newer versions of centos /bin/sh replaced by symlink to /bin/bash
Try adding this line in the begining your crontab file:
SHELL=/bin/bash
I think it is environment issue, crontab uses /bin/sh as a default shell, sh does not understand double brackets, it is also possiblle that in newer versions of centos /bin/sh replaced by symlink to /bin/bash
Try adding this line in the begining your crontab file:
SHELL=/bin/bash
answered Apr 15 at 3:37
badbukabadbuka
11
11
add a comment |
add a comment |
Yeats Raw is a new contributor. Be nice, and check out our Code of Conduct.
Yeats Raw is a new contributor. Be nice, and check out our Code of Conduct.
Yeats Raw is a new contributor. Be nice, and check out our Code of Conduct.
Yeats Raw is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f962873%2fcurl-bash-script-works-fine-in-shell-but-not-work-in-cronjob%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
There is a typo in your script as shown above. It appears a space between
Content-
andType
in thecurl
command. Check your original script.– Michael Hampton♦
Apr 13 at 0:49
typo fixed. it's not the original cause.
– Yeats Raw
Apr 13 at 4:23
Update the system.
– Michael Hampton♦
Apr 13 at 4:30
In the second line your are using
tmp/curl.tmp
where a/
is missing, so the logfile doesn't get deleted. Instead of the first two lines you could simply writeOUTPUT=/tmp/apm.log; rm -f $OUTPUT /curl.tmp; touch $OUTPUT
.– Freddy
Apr 13 at 5:20
Why do you use two files
/tmp/apm.log
and/tmp/curl.tmp
instead of one?– Freddy
Apr 13 at 5:26