# Ansible crontab special characters issue

**URL:** <https://forum.ansible.com/t/ansible-crontab-special-characters-issue/28985>\
**Category:** Ansible Developer\
**Created:** [November 9, 2018, 7:42am UTC](https://forum.ansible.com/t/ansible-crontab-special-characters-issue/28985 "2018-11-09T07:42:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rabeet\_Waqar](https://avatars.discourse-cdn.com/v4/letter/r/ea666f/32.png) [@Rabeet\_Waqar](https://forum.ansible.com/u/Rabeet_Waqar)\
**Post date:** [November 9, 2018, 7:42am UTC](https://forum.ansible.com/t/ansible-crontab-special-characters-issue/28985/1 "2018-11-09T07:42:32Z")

</div>

i am using ansible cron module

i am facing an issue when placing a job in ansible

ansible escapes special characters

my example job is:

(((( /usr/bin/php /var/www/file.php )))) \> /var/log/cron.stderr 2\>&1; if [$? -gt 0]; then echo CronRun @ Error; fi

i am unable to deploy exit status $? to the remote machine crontab. it converts special chars $? to

What to do please help

---

<div class="post-metadata">

**Author:** ![Rabeet\_Waqar](https://avatars.discourse-cdn.com/v4/letter/r/ea666f/32.png) [@Rabeet\_Waqar](https://forum.ansible.com/u/Rabeet_Waqar)\
**Post date:** [November 9, 2018, 7:58am UTC](https://forum.ansible.com/t/ansible-crontab-special-characters-issue/28985/2 "2018-11-09T07:58:57Z")

</div>



---

<div class="post-metadata">

**Author:** ![Ludovic\_Petetin](https://avatars.discourse-cdn.com/v4/letter/l/f14d63/32.png) [@Ludovic\_Petetin](https://forum.ansible.com/u/Ludovic_Petetin)\
**Post date:** [November 9, 2018, 8:09am UTC](https://forum.ansible.com/t/ansible-crontab-special-characters-issue/28985/3 "2018-11-09T08:09:19Z")

</div>

Hi,

could you please paste your task and your ansible version as I’ve just tested with this task :

- name: Install cron  
cron:  
name: test issue  
minute: 0  
hour: 0  
user: root  
job: “(((( /usr/bin/php /var/www/file.php )))) \> /var/log/cron.stderr 2\>&1; if [$? -gt 0]; then echo CronRun @ Error; fi”  
cron\_file: “test\_cron”

and Ansible version 2.7.0 and I have this as output

cat test\_cron  
#Ansible: test issue  
0 0 \* \* \* root (((( /usr/bin/php /var/www/file.php )))) \> /var/log/cron.stderr 2\>&1; if [$? -gt 0]; then echo CronRun @ Error; fi

Thanks

---

<div class="post-metadata">

**Author:** ![Rabeet\_Waqar](https://avatars.discourse-cdn.com/v4/letter/r/ea666f/32.png) [@Rabeet\_Waqar](https://forum.ansible.com/u/Rabeet_Waqar)\
**Post date:** [November 9, 2018, 9:25am UTC](https://forum.ansible.com/t/ansible-crontab-special-characters-issue/28985/4 "2018-11-09T09:25:19Z")

</div>

HI,

Thanks for your effor

i think my ansible version is previous its 2.0.0.2

Let me try and get back asap

---

<div class="post-metadata">

**Author:** ![Rabeet\_Waqar](https://avatars.discourse-cdn.com/v4/letter/r/ea666f/32.png) [@Rabeet\_Waqar](https://forum.ansible.com/u/Rabeet_Waqar)\
**Post date:** [November 9, 2018, 9:36am UTC](https://forum.ansible.com/t/ansible-crontab-special-characters-issue/28985/5 "2018-11-09T09:36:16Z")

</div>

I have tried with ansible version 2.7.1

Still same issue

i am constructing my command from nodejs backend

```auto
crontab_string += "(((( " + data.cron_details.job + " )))) > " + stderr + " 2>&1" ;
crontab_string += "; if [$? -gt 0]" +
    "; then echo CronRun @ Error >> " + log_file +
    "; date >> " + log_file +
    "; cat " + stderr + " >> " + log_file +
    "; else echo CronRun @ Success >> " + log_file +
    "; date >> " + log_file +
    "; fi";

```

---

<div class="post-metadata">

**Author:** ![Rabeet\_Waqar](https://avatars.discourse-cdn.com/v4/letter/r/ea666f/32.png) [@Rabeet\_Waqar](https://forum.ansible.com/u/Rabeet_Waqar)\
**Post date:** [November 9, 2018, 11:45am UTC](https://forum.ansible.com/t/ansible-crontab-special-characters-issue/28985/6 "2018-11-09T11:45:11Z")

</div>

Thanks

fixed it by escaping if [\$?\ -gt 0]

which results in if [$? -gt 0]
