# Linux command node for dates

**URL:** <https://discourse.nodered.org/t/linux-command-node-for-dates/65076>\
**Category:** General\
**Created:** [14 July 2022 07:33 UTC](https://discourse.nodered.org/t/linux-command-node-for-dates/65076 "2022-07-14T07:33:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rxdeath](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@rxdeath](https://discourse.nodered.org/u/rxdeath)\
**Post date:** [14 July 2022 07:33 UTC](https://discourse.nodered.org/t/linux-command-node-for-dates/65076/1 "2022-07-14T07:33:35Z")

</div>

i'm connected to a plc and am using avrdude to save firmware. i'm using a linux command node with the following syntax, and i want to add the date to the filename, so i know when the backup was made.  
ie:currently downloading as backup.hex i want backup20220714.hex

node contains as command: sudo avrdude -v -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:r:/home/pi/backup.hex:i

i am also writing firmware from a source and want to rename it (again with the date appended, so it can't accidentally be uploaded again in the future.  
ie: my read-in takes firmware.hex, i want to rename to firmware20220714.hex after it uploads

node contains as command:  
sudo avrdude -v -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:w:/home/pi/firmware.hex:i

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [14 July 2022 08:42 UTC](https://discourse.nodered.org/t/linux-command-node-for-dates/65076/2 "2022-07-14T08:42:37Z")

</div>

Is there a question here? What part are you having bother with?

To make dynamic file names use moment (or change node) to generate the date part. Use a change node or function node to generate the `msg.filename` - put the data in `msg.payload` - send it to a file write node.

For generating the date part there are many options  
function code `new Date().toISOString().replace(/-/g,"").substring(0,8)` --\> "20220714"  
change node (JSONata) `$moment().format("YYYYMMDD")` --\> "20220714"

---

<div class="post-metadata">

**Author:** ![rxdeath](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@rxdeath](https://discourse.nodered.org/u/rxdeath)\
**Post date:** [14 July 2022 09:15 UTC](https://discourse.nodered.org/t/linux-command-node-for-dates/65076/3 "2022-07-14T09:15:05Z")

</div>

i'm using a linux command node, and i can generate the date in a function node, but i can't get that variable into the linxu command node command i have posted. (saving firmware)

second question was renaming file after i upload it to plc using hte second command (again linux command node because i'm running avrdude to upload/backup firmware on a plc)

---

<div class="post-metadata">

**Author:** ![rxdeath](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@rxdeath](https://discourse.nodered.org/u/rxdeath)\
**Post date:** [14 July 2022 19:30 UTC](https://discourse.nodered.org/t/linux-command-node-for-dates/65076/4 "2022-07-14T19:30:01Z")

</div>

here are the 2 nodes

```auto
[
    {
        "id": "f67bf870512d4292",
        "type": "exec",
        "z": "05078416059076a6",
        "command": "sudo avrdude -v -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:r:/home/pi/backup.hex:i",
        "addpay": false,
        "append": "",
        "useSpawn": "true",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "firmwareCMDsave",
        "x": 2490,
        "y": 240,
        "wires": [
            [],
            [],
            []
        ]
    },
    {
        "id": "6c5520274b9bf30c",
        "type": "exec",
        "z": "05078416059076a6",
        "command": "sudo avrdude -v -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:w:/home/pi/firmware.hex:i",
        "addpay": false,
        "append": "",
        "useSpawn": "true",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "firmwareCMDwrite",
        "x": 2490,
        "y": 400,
        "wires": [
            [],
            [],
            []
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 July 2022 20:21 UTC](https://discourse.nodered.org/t/linux-command-node-for-dates/65076/5 "2022-07-14T20:21:48Z")

</div>

If you want the command details to be dynamic then leave the command field in the exec node empty, select Add Payload and pass the command in msg.payload. Then you can build the payload however you like, by using a Template node for example.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [12 September 2022 20:22 UTC](https://discourse.nodered.org/t/linux-command-node-for-dates/65076/6 "2022-09-12T20:22:07Z")

</div>

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