terminal file output

Joined
Aug 17, 2017
Messages
4
Reaction score
0
Points
1
Hello

I'm new! Thanks for the space :)

I was looking for some help on how to add a date and time to a filename when outputting it via command line.

I can't make it to work, does anyone knows how to do it please?
log app from here > '/Volumes/1TB/db/db.+DATE: %Y-%m-%d.backup'

it just print out the characters...
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,765
Reaction score
2,105
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Welcome to Mac-Forums..

To do this at the command line, you'll want to call the 'date' command with a string telling it how you want the output, for example

Code:
date '+%Y-%m-%d'

This will output 2017-08-17 today.

If you want to use that format and append it to a file you would do

Code:
touch my_file_`date '+%Y-%m-%d'`.backup

This will create a file called my_file_2017-08-17.backup in the current directory. Note that you have to surround the date command in backquotes (the key on the left of the 1 on your keyboard)..
 
OP
D
Joined
Aug 17, 2017
Messages
4
Reaction score
0
Points
1
Ah thank you so much!

How do you know that? I wasn't able to find anything on the man page... ://
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,765
Reaction score
2,105
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Ah thank you so much!

How do you know that? I wasn't able to find anything on the man page... ://

A career in software engineering...:) Been doing things at the command line and scripting with Bash, AWK, Sed and so on for 15+ years..
 
OP
D
Joined
Aug 17, 2017
Messages
4
Reaction score
0
Points
1
A career in software engineering...:) Been doing things at the command line and scripting with Bash, AWK, Sed and so on for 15+ years..

Definitely a good thing.

It's a bit wired with crontab. Seems mine is a tmp file full of tildaes. Is that correct?

I made a launchd script to backup the postgreSQL database at 03:01am every weekday but I would be more comfrotable to use crontab

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.dbbackup.plist</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Volumes/.../_postgreSQL-backup/script/backup.sh</string>
    </array>
    <key>StartCalendarInterval</key>
<!--  Weekdays are 1 - 5; Sunday is 0 and 7   -->
    <array>
        <dict>
            <key>Weekday</key>
            <integer>1</integer>
            <key>Hour</key>
            <integer>3</integer>
            <key>Minute</key>
            <integer>1</integer>
        </dict>
        <dict>
            <key>Weekday</key>
            <integer>2</integer>
            <key>Hour</key>
            <integer>3</integer>
            <key>Minute</key>
            <integer>1</integer>
        </dict>
        <dict>
            <key>Weekday</key>
            <integer>3</integer>
            <key>Hour</key>
            <integer>3</integer>
            <key>Minute</key>
            <integer>1</integer>
        </dict>
        <dict>
            <key>Weekday</key>
            <integer>4</integer>
            <key>Hour</key>
            <integer>3</integer>
            <key>Minute</key>
            <integer>1</integer>
        </dict>
        <dict>
            <key>Weekday</key>
            <integer>5</integer>
            <key>Hour</key>
            <integer>3</integer>
            <key>Minute</key>
            <integer>1</integer>
        </dict>
    </array>
</dict>
</plist>
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top