# Filter applied to Segments, but contacts are not getting linked to the segment

**URL:** <https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847>\
**Category:** Product Support\
**Created:** [August 5, 2023, 6:57am UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847 "2023-08-05T06:57:22Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssdesign](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ssdesign/32/10291_2.png) [@ssdesign](https://forum.mautic.org/u/ssdesign)\
**Post date:** [August 5, 2023, 6:57am UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847/1 "2023-08-05T06:57:22Z")

</div>

MAUTIC  
My Mautic version is: 4.0.0  
My PHP version is: PHP Version 7.4.33  
My Database type and version is: MariaDB (10.6.12-MariaDB-0ubuntu0.22.04.1)

**Your problem**  
My problem is:

1. I added two contacts manually. I added tags to both contact.
2. Then I created a new Segment and added a filter for the Tag values I just assigned to the contacts.
3. After that, I was expecting the two contacts to be linked to the segment, but the segment still says “No contacts”

What can I do to fix this? I am just staring off with Mautic and this is just Day-1 for me 🙂  
I read somewhere that I may need to run cron job of some sort, but I could not find the information for it.

I am running Mautic on AWS EC2, so any related guidance would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [August 6, 2023, 6:23am UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847/2 "2023-08-06T06:23:46Z")

</div>

Hi,  
Based on your other post you probably figured out, that your cronjobs are not running.  
Do you have an ssh access to your server?

---

<div class="post-metadata">

**Author:** ![ssdesign](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ssdesign/32/10291_2.png) [@ssdesign](https://forum.mautic.org/u/ssdesign)\
**Post date:** [August 6, 2023, 7:11am UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847/3 "2023-08-06T07:11:12Z")

</div>

Hi @joeyk  
Thanks for your reply.  
Yes I have SSH access.  
I also added the cron job to the server like this:  
`* * * * * /usr/local/bin/php /var/www/html/mautic/bin/console mautic:segments:update —env=prod > /dev/null 2>&1`

When I do crontab -l I can see this line of code. But still the segment is not getting updated with tagged contacts.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [August 6, 2023, 5:03pm UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847/4 "2023-08-06T17:03:14Z")

</div>

Can you run this code in the ssh console without the

> /dev/null 2\>&1

ending and see the result

---

<div class="post-metadata">

**Author:** ![ssdesign](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ssdesign/32/10291_2.png) [@ssdesign](https://forum.mautic.org/u/ssdesign)\
**Post date:** [August 6, 2023, 10:45pm UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847/5 "2023-08-06T22:45:59Z")

</div>

Just tried that too.  
Still its not working ☹  
Everything else is working fine on Mautic installation.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [August 7, 2023, 6:14am UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847/6 "2023-08-07T06:14:48Z")

</div>

Hi,  
could you plz share the result what you recieve back in command line?  
Also: you said everything else is working.  
Does campaign triggering working?

---

<div class="post-metadata">

**Author:** ![ssdesign](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ssdesign/32/10291_2.png) [@ssdesign](https://forum.mautic.org/u/ssdesign)\
**Post date:** [August 7, 2023, 6:27am UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847/7 "2023-08-07T06:27:46Z")

</div>

> [@ssdesign](#):
>
> - 
> - 
> - 
> - 
> - /usr/local/bin/php /var/www/html/mautic/bin/console mautic:segments:update

Hi, Did you mean running this code directly in SSH?  
I just did that.  
I get command not found.

This is what I ran:

```auto
* * * * * /usr/local/bin/php /var/www/html/mautic/bin/console mautic:segments:update

```

---

<div class="post-metadata">

**Author:** ![ssdesign](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ssdesign/32/10291_2.png) [@ssdesign](https://forum.mautic.org/u/ssdesign)\
**Post date:** [August 7, 2023, 6:35am UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847/8 "2023-08-07T06:35:43Z")

</div>

Oh Sorry my mistake,  
I ran this script

```auto
/var/www/html/mautic/bin/console mautic:segments:update

```

and got this result:

```auto
1 total contact(s) to be added in batches of 300
 1/1 [============================] 100%
0 total contact(s) to be removed in batches of 300
1 contact(s) affected

```

The script ran successfully and updated the segment with a contact that was tagged.

So looks like if I execute through SSH, its working. Somehow the cron job is not executing on its own.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [August 7, 2023, 6:36am UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847/9 "2023-08-07T06:36:57Z")

</div>

Hello,  
Dont run the stars in your command line. That is for the crontab.  
Run this:

`/usr/local/bin/php /var/www/html/mautic/bin/console mautic:segments:update`

or

`php /var/www/html/mautic/bin/console mautic:segments:update`

---

<div class="post-metadata">

**Author:** ![ssdesign](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ssdesign/32/10291_2.png) [@ssdesign](https://forum.mautic.org/u/ssdesign)\
**Post date:** [August 7, 2023, 6:45am UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847/10 "2023-08-07T06:45:38Z")

</div>

Ok, So I tried the following:

```auto
/usr/local/bin/php /var/www/html/mautic/bin/console mautic:segments:update

```

No such file or directory

```auto
php /var/www/html/mautic/bin/console mautic:segments:update

```

Executed successfully.

So I did crontab -e  
Edited my cron job string to the one above that worked.  
SSH said: “crontab: installing new crontab”  
I waited a few minutes and checked, but the segment was not updated ☹

Not sure what I am doing wrong here…

---

<div class="post-metadata">

**Author:** ![ssdesign](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ssdesign/32/10291_2.png) [@ssdesign](https://forum.mautic.org/u/ssdesign)\
**Post date:** [August 7, 2023, 6:54am UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847/11 "2023-08-07T06:54:33Z")

</div>

Ok looks like it is working now.  
Thanks a lot for brainstorming this with me 🙂  
Only problem I noticed is that once the script runs and it adds a contact to the segment and later if I remove the contact from segment manually, it does not add that contact again.

Not sure how to solve that 🙂

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [August 7, 2023, 7:41am UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847/12 "2023-08-07T07:41:35Z")

</div>

This is how it should work.  
Once a contact is manually removed (you must have a reason to do so), it will be immune to the segment filters. This is your own protection not to create infinate loops and crash your own server.

---

<div class="post-metadata">

**Author:** ![ssdesign](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ssdesign/32/10291_2.png) [@ssdesign](https://forum.mautic.org/u/ssdesign)\
**Post date:** [August 7, 2023, 7:50am UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847/13 "2023-08-07T07:50:55Z")

</div>

Thanks a lot for your explanation. Really appreciate your help 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/1X/43c63600fe51440378769136903f1fa2a9a34102.png) [@system](https://forum.mautic.org/u/system)\
**Post date:** [August 8, 2023, 7:51pm UTC](https://forum.mautic.org/t/filter-applied-to-segments-but-contacts-are-not-getting-linked-to-the-segment/28847/14 "2023-08-08T19:51:40Z")

</div>

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.
