Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9021857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:21:23+00:00 2026-06-16T05:21:23+00:00

This is my script : set -x PTH=/data0101/track_logs cd /data0101/track_logs if [[ `ls -lrth

  • 0

This is my script :

    set -x

    PTH=/data0101/track_logs
    cd /data0101/track_logs

    if [[ `ls -lrth | grep IMEI_TRACK | wc -l` -gt 0 ]];
    then
       FILE_COUNT=`ls -lrth | grep IMEI_TRACK | wc -l`

       YEAR=`date | awk '{print $6}'`
       mkdir $PTH/$YEAR

       MONTH=`date | awk '{print $2}'`
       mkdir $PTH/$YEAR/$MONTH

       DAY=`date | awk '{print $3}'`

       HOUR=`date | awk '{print $4}' | cut -d":" -f 1`
       if [[ $HOUR -ne 0 ]];
       then
          HR=$(( $HOUR - 1 ))
       else
          DAY=$(( $DAY - 1 ))
          HR=23
          mkdir $PTH/$YEAR/$MONTH/$DAY
       fi
       case $HR  in
            00-23) for (( i=1;i<=$FILE_COUNT;i++ ))
                   do
                    chk=`ls -lrth | grep IMEI_TRACK | head -$i | tail -1 | awk '{print    $8}' | cut -d: -f1`
                    FILE=`ls -lrth | grep IMEI_TRACK |  awk '{print $9}'`
                    if [[ $chk -eq $HR ]];
                    then
                       mkdir $PTH/$YEAR/$MONTH/$DAY/$HR
                       mv $FILE $PTH/$YEAR/$MONTH/$DAY/$HR/
                    else
                       break
                    fi
                   done ;;


       esac
    fi

When I run the script this is what I get:

    + PTH=/data0101/track_logs
    + cd /data0101/track_logs
    ++ ls -lrth
    ++ grep IMEI_TRACK
    ++ wc -l
    + [[ 200 -gt 0 ]]
    ++ ls -lrth
    ++ grep IMEI_TRACK
    ++ wc -l
    + FILE_COUNT=200
    ++ date
    ++ awk '{print $6}'
    + YEAR=2012
    + mkdir /data0101/track_logs/2012
    mkdir: cannot create directory `/data0101/track_logs/2012': File exists
    ++ date
    ++ awk '{print $2}'
    + MONTH=Dec
    + mkdir /data0101/track_logs/2012/Dec
    mkdir: cannot create directory `/data0101/track_logs/2012/Dec': File exists
    ++ date
    ++ awk '{print $3}'
    + DAY=20
    ++ date
    ++ awk '{print $4}'
    ++ cut -d: -f 1
    + HOUR=14
    + [[ 14 -ne 0 ]]
    + HR=13
    + case $HR in

This clearly shows that this script is not getting further than the case statement. Is there anything wrong with my case construct. Kindly help. Also suggestions on overall development of the script is also welcome.

I tried using the range in my case construct like this:

    case $HR  in
                [00-23]) for (( i=1;i<=$FILE_COUNT;i++ ))
                           do
                            chk=`ls -lrth | grep IMEI_TRACK | head -$i | tail -1 | awk '{print    $8}' | cut -d: -f1`
                            FILE=`ls -lrth | grep IMEI_TRACK |  awk '{print $9}'`
                            if [[ $chk -eq $HR ]];
                            then
                               mkdir $PTH/$YEAR/$MONTH/$DAY/$HR
                               mv $FILE $PTH/$YEAR/$MONTH/$DAY/$HR/
                            else
                               break
                            fi
                           done ;;


      esac

bu this doesn’t help as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:21:24+00:00Added an answer on June 16, 2026 at 5:21 am

    You need to check each digit separate, something like [0-2][0-9], you can also use find instead of looping over the files, mkdir with -p option to create parent directories if necessary, and multiple variable assignment using read:

    #!/bin/bash
    
    PTH="/data0101/track_logs"
    cd "$PTH"
    
    if [[ $(ls -lrth | grep IMEI_TRACK | wc -l) -gt 0 ]]; then
        DATE=$(date +"%Y %m %d %H")
        DIR=${DATE// /\/}
        read YEAR MONTH DAY HOUR <<<$DATE
    
        case $HOUR  in
            [0-2][0-9]) mkdir -p "$DIR"
                        find ./ -mtime -1 -name "*IMEI_TRACK*" -type f -exec mv "{}" "$DIR" \;;;
    
        esac
    fi
    

    You don’t need to check the hour if you just put this script in your /etc/cron.hourly folder, then your script would look something like this:

    #!/bin/bash
    
    PTH="/data0101/track_logs"
    cd "$PTH"
    
    DIR=$(date +"%Y/%m/%d/%H")
    mkdir "$DIR"
    
    find ./ -mtime -1 -name "*IMEI_TRACK*" -type f -exec mv "{}" "$DIR" \;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this shell script inside applescript: set Date to (do shell script date
I have this script set up that echoes all relevant users in a database
in my site i want to set default page to open, using this script
I have this sql script DECLARE @XmlStr XML SET @XmlStr = '<EmployeeID> <Employee>48f9194f-8d46-e111-8849-0050569445f1</Employee> <Employee>7d725561-8d46-e111-8849-0050569445f2</Employee>
I am currently using the following script to set this value as a String:
This is boggling my mind today. I have a bash script to set a
I have set up a php script to receive url data like this: http://giffgaff.liamwli.co.uk/?name=liamwli
I have a script that starts Tomcat and it looks like this: rem set
I have this little batch script: SET @var = GREG ECHO %@var% PAUSE When
I have this script saved in test.vbs: Set FSO = CreateObject(Scripting.FileSystemObject) Set File =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.