escaping hash (#) in cron










0















The following line works in cron:



* * * * * /usr/bin/mosquitto_pub -h test.mosquitto.org -p 1883 -u dragino -t /MyExample/Topic -m "GPING-GPING-4-GPING-GPING"


This one doesn´t:



* * * * * /usr/bin/mosquitto_pub -h test.mosquitto.org -p 1883 -u dragino -t /MyExample/Topic -m "GPING#GPING#4#GPING#GPING"


Notice I changed the - characters to # inside the message. I understand that the # character needs scaping, but how? # didn't work.










share|improve this question
























  • which cron are you using?

    – kvantour
    Nov 13 '18 at 13:27











  • it´s the cron used in Dragino products (Arduino Yun based, OpenWRT). Do you want me to check some specific version? If so, how can I check it? Thanks.

    – Daniel Fernandes
    Nov 13 '18 at 17:02















0















The following line works in cron:



* * * * * /usr/bin/mosquitto_pub -h test.mosquitto.org -p 1883 -u dragino -t /MyExample/Topic -m "GPING-GPING-4-GPING-GPING"


This one doesn´t:



* * * * * /usr/bin/mosquitto_pub -h test.mosquitto.org -p 1883 -u dragino -t /MyExample/Topic -m "GPING#GPING#4#GPING#GPING"


Notice I changed the - characters to # inside the message. I understand that the # character needs scaping, but how? # didn't work.










share|improve this question
























  • which cron are you using?

    – kvantour
    Nov 13 '18 at 13:27











  • it´s the cron used in Dragino products (Arduino Yun based, OpenWRT). Do you want me to check some specific version? If so, how can I check it? Thanks.

    – Daniel Fernandes
    Nov 13 '18 at 17:02













0












0








0








The following line works in cron:



* * * * * /usr/bin/mosquitto_pub -h test.mosquitto.org -p 1883 -u dragino -t /MyExample/Topic -m "GPING-GPING-4-GPING-GPING"


This one doesn´t:



* * * * * /usr/bin/mosquitto_pub -h test.mosquitto.org -p 1883 -u dragino -t /MyExample/Topic -m "GPING#GPING#4#GPING#GPING"


Notice I changed the - characters to # inside the message. I understand that the # character needs scaping, but how? # didn't work.










share|improve this question
















The following line works in cron:



* * * * * /usr/bin/mosquitto_pub -h test.mosquitto.org -p 1883 -u dragino -t /MyExample/Topic -m "GPING-GPING-4-GPING-GPING"


This one doesn´t:



* * * * * /usr/bin/mosquitto_pub -h test.mosquitto.org -p 1883 -u dragino -t /MyExample/Topic -m "GPING#GPING#4#GPING#GPING"


Notice I changed the - characters to # inside the message. I understand that the # character needs scaping, but how? # didn't work.







cron escaping






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 14:55









kvantour

8,74831330




8,74831330










asked Nov 13 '18 at 13:02









Daniel FernandesDaniel Fernandes

1




1












  • which cron are you using?

    – kvantour
    Nov 13 '18 at 13:27











  • it´s the cron used in Dragino products (Arduino Yun based, OpenWRT). Do you want me to check some specific version? If so, how can I check it? Thanks.

    – Daniel Fernandes
    Nov 13 '18 at 17:02

















  • which cron are you using?

    – kvantour
    Nov 13 '18 at 13:27











  • it´s the cron used in Dragino products (Arduino Yun based, OpenWRT). Do you want me to check some specific version? If so, how can I check it? Thanks.

    – Daniel Fernandes
    Nov 13 '18 at 17:02
















which cron are you using?

– kvantour
Nov 13 '18 at 13:27





which cron are you using?

– kvantour
Nov 13 '18 at 13:27













it´s the cron used in Dragino products (Arduino Yun based, OpenWRT). Do you want me to check some specific version? If so, how can I check it? Thanks.

– Daniel Fernandes
Nov 13 '18 at 17:02





it´s the cron used in Dragino products (Arduino Yun based, OpenWRT). Do you want me to check some specific version? If so, how can I check it? Thanks.

– Daniel Fernandes
Nov 13 '18 at 17:02












2 Answers
2






active

oldest

votes


















0














Escape all # with , as # denotes a comment in bash-scripts such as cron runs.
# should allow the script to run.






share|improve this answer























  • As I said "#" didn´t work, but thanks for your idea.

    – Daniel Fernandes
    Nov 13 '18 at 16:58


















0














This statement is incorrect:




Blank lines, leading spaces, and tabs are ignored. Lines whose first non-white space character is a <pound-sign> (#) are comments and are not processed. Note that comments are not allowed on the same line as cron commands since they are considered a part of the command. Similarly, comments are not allowed on the same line as environment variable settings.



source: man 5 crontab




You can easily test this with:



* * * * * echo "#" > ~/foo.txt


Your issue is most likely related to mosquitto_pub. Although unversed in the topic, it seems that you can only have a single # in your message and it should be at the end.



An alternative solution could be to create a script /path/to/run_cronscript.sh which contains:



#!/usr/bin/env bash

/usr/bin/mosquitto_pub -h test.mosquitto.org -p 1883 -u dragino -t /MyExample/Topic -m "GPING#GPING#4#GPING#GPING"


and adjust your crontab as:



* * * * * /path/to/run_cronscript.sh





share|improve this answer

























  • You can only have 1 # in the topic and it must be at the end, you can have as many # as you want in the message payload

    – hardillb
    Nov 13 '18 at 14:47











  • If I use the command with the "#" directly from command line it works OK. Just inside cron it doesn´t work. But thanks for your input.

    – Daniel Fernandes
    Nov 13 '18 at 17:00











  • @DanielFernandes What you could do is to write your moquitto line in a script and just execute the script.

    – kvantour
    Nov 14 '18 at 16:11











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281617%2fescaping-hash-in-cron%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Escape all # with , as # denotes a comment in bash-scripts such as cron runs.
# should allow the script to run.






share|improve this answer























  • As I said "#" didn´t work, but thanks for your idea.

    – Daniel Fernandes
    Nov 13 '18 at 16:58















0














Escape all # with , as # denotes a comment in bash-scripts such as cron runs.
# should allow the script to run.






share|improve this answer























  • As I said "#" didn´t work, but thanks for your idea.

    – Daniel Fernandes
    Nov 13 '18 at 16:58













0












0








0







Escape all # with , as # denotes a comment in bash-scripts such as cron runs.
# should allow the script to run.






share|improve this answer













Escape all # with , as # denotes a comment in bash-scripts such as cron runs.
# should allow the script to run.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 13:24









Fluid SenseFluid Sense

53




53












  • As I said "#" didn´t work, but thanks for your idea.

    – Daniel Fernandes
    Nov 13 '18 at 16:58

















  • As I said "#" didn´t work, but thanks for your idea.

    – Daniel Fernandes
    Nov 13 '18 at 16:58
















As I said "#" didn´t work, but thanks for your idea.

– Daniel Fernandes
Nov 13 '18 at 16:58





As I said "#" didn´t work, but thanks for your idea.

– Daniel Fernandes
Nov 13 '18 at 16:58













0














This statement is incorrect:




Blank lines, leading spaces, and tabs are ignored. Lines whose first non-white space character is a <pound-sign> (#) are comments and are not processed. Note that comments are not allowed on the same line as cron commands since they are considered a part of the command. Similarly, comments are not allowed on the same line as environment variable settings.



source: man 5 crontab




You can easily test this with:



* * * * * echo "#" > ~/foo.txt


Your issue is most likely related to mosquitto_pub. Although unversed in the topic, it seems that you can only have a single # in your message and it should be at the end.



An alternative solution could be to create a script /path/to/run_cronscript.sh which contains:



#!/usr/bin/env bash

/usr/bin/mosquitto_pub -h test.mosquitto.org -p 1883 -u dragino -t /MyExample/Topic -m "GPING#GPING#4#GPING#GPING"


and adjust your crontab as:



* * * * * /path/to/run_cronscript.sh





share|improve this answer

























  • You can only have 1 # in the topic and it must be at the end, you can have as many # as you want in the message payload

    – hardillb
    Nov 13 '18 at 14:47











  • If I use the command with the "#" directly from command line it works OK. Just inside cron it doesn´t work. But thanks for your input.

    – Daniel Fernandes
    Nov 13 '18 at 17:00











  • @DanielFernandes What you could do is to write your moquitto line in a script and just execute the script.

    – kvantour
    Nov 14 '18 at 16:11
















0














This statement is incorrect:




Blank lines, leading spaces, and tabs are ignored. Lines whose first non-white space character is a <pound-sign> (#) are comments and are not processed. Note that comments are not allowed on the same line as cron commands since they are considered a part of the command. Similarly, comments are not allowed on the same line as environment variable settings.



source: man 5 crontab




You can easily test this with:



* * * * * echo "#" > ~/foo.txt


Your issue is most likely related to mosquitto_pub. Although unversed in the topic, it seems that you can only have a single # in your message and it should be at the end.



An alternative solution could be to create a script /path/to/run_cronscript.sh which contains:



#!/usr/bin/env bash

/usr/bin/mosquitto_pub -h test.mosquitto.org -p 1883 -u dragino -t /MyExample/Topic -m "GPING#GPING#4#GPING#GPING"


and adjust your crontab as:



* * * * * /path/to/run_cronscript.sh





share|improve this answer

























  • You can only have 1 # in the topic and it must be at the end, you can have as many # as you want in the message payload

    – hardillb
    Nov 13 '18 at 14:47











  • If I use the command with the "#" directly from command line it works OK. Just inside cron it doesn´t work. But thanks for your input.

    – Daniel Fernandes
    Nov 13 '18 at 17:00











  • @DanielFernandes What you could do is to write your moquitto line in a script and just execute the script.

    – kvantour
    Nov 14 '18 at 16:11














0












0








0







This statement is incorrect:




Blank lines, leading spaces, and tabs are ignored. Lines whose first non-white space character is a <pound-sign> (#) are comments and are not processed. Note that comments are not allowed on the same line as cron commands since they are considered a part of the command. Similarly, comments are not allowed on the same line as environment variable settings.



source: man 5 crontab




You can easily test this with:



* * * * * echo "#" > ~/foo.txt


Your issue is most likely related to mosquitto_pub. Although unversed in the topic, it seems that you can only have a single # in your message and it should be at the end.



An alternative solution could be to create a script /path/to/run_cronscript.sh which contains:



#!/usr/bin/env bash

/usr/bin/mosquitto_pub -h test.mosquitto.org -p 1883 -u dragino -t /MyExample/Topic -m "GPING#GPING#4#GPING#GPING"


and adjust your crontab as:



* * * * * /path/to/run_cronscript.sh





share|improve this answer















This statement is incorrect:




Blank lines, leading spaces, and tabs are ignored. Lines whose first non-white space character is a <pound-sign> (#) are comments and are not processed. Note that comments are not allowed on the same line as cron commands since they are considered a part of the command. Similarly, comments are not allowed on the same line as environment variable settings.



source: man 5 crontab




You can easily test this with:



* * * * * echo "#" > ~/foo.txt


Your issue is most likely related to mosquitto_pub. Although unversed in the topic, it seems that you can only have a single # in your message and it should be at the end.



An alternative solution could be to create a script /path/to/run_cronscript.sh which contains:



#!/usr/bin/env bash

/usr/bin/mosquitto_pub -h test.mosquitto.org -p 1883 -u dragino -t /MyExample/Topic -m "GPING#GPING#4#GPING#GPING"


and adjust your crontab as:



* * * * * /path/to/run_cronscript.sh






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 16:14

























answered Nov 13 '18 at 13:42









kvantourkvantour

8,74831330




8,74831330












  • You can only have 1 # in the topic and it must be at the end, you can have as many # as you want in the message payload

    – hardillb
    Nov 13 '18 at 14:47











  • If I use the command with the "#" directly from command line it works OK. Just inside cron it doesn´t work. But thanks for your input.

    – Daniel Fernandes
    Nov 13 '18 at 17:00











  • @DanielFernandes What you could do is to write your moquitto line in a script and just execute the script.

    – kvantour
    Nov 14 '18 at 16:11


















  • You can only have 1 # in the topic and it must be at the end, you can have as many # as you want in the message payload

    – hardillb
    Nov 13 '18 at 14:47











  • If I use the command with the "#" directly from command line it works OK. Just inside cron it doesn´t work. But thanks for your input.

    – Daniel Fernandes
    Nov 13 '18 at 17:00











  • @DanielFernandes What you could do is to write your moquitto line in a script and just execute the script.

    – kvantour
    Nov 14 '18 at 16:11

















You can only have 1 # in the topic and it must be at the end, you can have as many # as you want in the message payload

– hardillb
Nov 13 '18 at 14:47





You can only have 1 # in the topic and it must be at the end, you can have as many # as you want in the message payload

– hardillb
Nov 13 '18 at 14:47













If I use the command with the "#" directly from command line it works OK. Just inside cron it doesn´t work. But thanks for your input.

– Daniel Fernandes
Nov 13 '18 at 17:00





If I use the command with the "#" directly from command line it works OK. Just inside cron it doesn´t work. But thanks for your input.

– Daniel Fernandes
Nov 13 '18 at 17:00













@DanielFernandes What you could do is to write your moquitto line in a script and just execute the script.

– kvantour
Nov 14 '18 at 16:11






@DanielFernandes What you could do is to write your moquitto line in a script and just execute the script.

– kvantour
Nov 14 '18 at 16:11


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • 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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281617%2fescaping-hash-in-cron%23new-answer', 'question_page');

);

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







Popular posts from this blog

Darth Vader #20

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Ondo