# Auto Run And Record

**URL:** <https://discourse.asciinema.org/t/auto-run-and-record/645>\
**Category:** Help\
**Created:** [June 20, 2022, 1:48pm UTC](https://discourse.asciinema.org/t/auto-run-and-record/645 "2022-06-20T13:48:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nimafanniasl](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/nimafanniasl/32/377_2.png) [@nimafanniasl](https://discourse.asciinema.org/u/nimafanniasl)\
**Post date:** [June 20, 2022, 1:48pm UTC](https://discourse.asciinema.org/t/auto-run-and-record/645/1 "2022-06-20T13:48:07Z")

</div>

Hello  
I Have A Virtual machine That I Connect To With ssh! I Want When A Bash Started, Recording Starts!  
When I put the command in bashrc, every time a bash is executed, an infinite loop is created that starts recording! How can I solve this problem?

---

<div class="post-metadata">

**Author:** ![rkazak](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/rkazak/32/375_2.png) [@rkazak](https://discourse.asciinema.org/u/rkazak)\
**Post date:** [June 26, 2022, 5:16pm UTC](https://discourse.asciinema.org/t/auto-run-and-record/645/2 "2022-06-26T17:16:17Z")

</div>

When you login/connect initially set a flag/lock. Include code to check the existence of the flag/lock every time you login?

---

<div class="post-metadata">

**Author:** ![ku1ik](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.asciinema.org/ku1ik/32/171_2.png) [@ku1ik](https://discourse.asciinema.org/u/ku1ik)\
**Post date:** [April 20, 2024, 3:22pm UTC](https://discourse.asciinema.org/t/auto-run-and-record/645/3 "2024-04-20T15:22:52Z")

</div>

What @rkazak suggested is what people do in this case.

In fact, asciinema sets `ASCIINEMA_REC=1` environment variable when you record.

You can put a conditional in your shell config file to check for this variable and start `asciinema rec <filename>` only when it’s not set.
