Perplexity Ai writing scripts

Started by neurosis, September 10, 2024, 10:03 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

neurosis

lol

Just for fun I asked perplexity ai to write a batch script that will back up a database and delete any backups older than 14 days.  It wrote the script in less than one second. 

I wish this had been around when the forums started.  :lol: 


The exact question   

Quotecan you write a bash script that will back up a sql database, date the backups, and delete any backup older than 14 days?




bash
#!/bin/bash

# Configuration
DB_USER="your_username"
DB_PASSWORD="your_password"
DB_NAME="your_database_name"
BACKUP_DIR="/path/to/backup/directory"
DAYS_TO_KEEP=14

# Create backup directory if it doesn't exist
mkdir -p "$BACKUP_DIR"

# Generate timestamp for the backup file
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")

# Backup filename
BACKUP_FILE="$BACKUP_DIR/${DB_NAME}_${TIMESTAMP}.sql"

# Perform the database backup
mysqldump -u "$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" > "$BACKUP_FILE"

# Check if the backup was successful
if [ $? -eq 0 ]; then
    echo "Backup created successfully: $BACKUP_FILE"
   
    # Compress the backup file
    gzip "$BACKUP_FILE"
    echo "Backup compressed: $BACKUP_FILE.gz"
else
    echo "Error: Database backup failed"
    exit 1
fi

# Delete backups older than 14 days
find "$BACKUP_DIR" -name "${DB_NAME}_*.sql.gz" -type f -mtime +$DAYS_TO_KEEP -delete

echo "Deleted backups older than $DAYS_TO_KEEP days"
Like Like x 1 Funny Funny x 1 View List
I'll go back to being a conservative, when conservatives go back to being conservative.

Incogneeto

I asked it to "Find my next wife"

I'm getting a Loud Ear Splitting Whine and Smoke?? :o
Like Like x 1 Funny Funny x 1 View List

neurosis

When I asked it to do this same thing months ago I had to keep asking it questions until it got everything right.  It does more than I asked it to probably based on popular requests. 
I'll go back to being a conservative, when conservatives go back to being conservative.

RobertELee

Quote from: Incogneeto on September 10, 2024, 10:13 AMI asked it to "Find my next wife"

I'm getting a Loud Ear Splitting Whine and Smoke?? :o

Funny Funny x 1 View List


neurosis

This is what I tell my girlfriend she sounds like when she's drunk.  :lol: 


https://www.barbneal.com/wp-content/uploads/fogleg04.mp3
I'll go back to being a conservative, when conservatives go back to being conservative.


Tim Johnson

Mazak has a mill-turn that writes a machining program using the part model alone with AI.
Shock Shock x 1 View List
FJB