Select Your Language

Infrastructure and Management

Cloud Computing

Storage

Runtimes

Integration and Automation

  • Comments
    • Tags

    Questions regarding script moving of dated fles.

    Posted on

    Good Day,

    I have previous written a script that allowed me to do clean up of my /var/log/messages file. The Script provides the ip address of each machine and catted the message file before it was cleaned and rotated. The file contents of the log file for each of the 69 clients as backup and lists the file as ip address.txt. This is working as I wanted.

    What i want to do now is append the date that the script was run to the front of the file keeping the ip address also. This is the code I found for that.

    ! /bin/bash

    find . -maxdepth 1 -type f | \
    cut -c3- | \
    grep -v '^.' | \
    grep -v '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]' | \
    xargs -n 1 -I {} echo mv "{}" "

    date +"%Y-%m-%d"
    {}"
    mkdir
    date +%Y_%m_%d

    exit;

    I would like to create a directory for that date and move all the files to that directory. Also I would like this to happen each time the script is run.

    Is there a quick way to do this? I am a newbie so shell scripting is starting to be something I will b doing a lot of so any pointers you have will be much appreciated.

    Thanks,

    Jon.

    by

    points

    Responses

    Red Hat LinkedIn YouTube Facebook X, formerly Twitter

    Quick Links

    Help

    Site Info

    Related Sites

    © 2026 Red Hat