Link to home
Start Free TrialLog in
Avatar of bje
bjeFlag for United States of America

asked on

determine the day and hour and if matches Friday13 then mv a file

Hello,
I am working on moving a file if the day and time are equal to Friday at 13:00.

This  what I have, (the directories are defined in a config file)

cp $file ${archive_dir}
cp $file ${first_dir}
    if [ ``date + %A%l` | egrep -o "Friday13"` ]
        then
         mv $file ${second_dir}
        else
         rm -f $file
   fi

I know my syntax is incorrect not sure where.  Thank you for the assistance.

Brian
Avatar of Phonebuff
Phonebuff
Flag of United States of America image

Here is a couple of lines of code from one of my scripts --  Hope this points you in the right direction.

ArchMonth=$(date --date='1 month ago' +"%b")   # Past

ArchDir=$(date --date='1 month ago' +"%b%Y")

echo $ArchMonth
echo $ArchDir

Open in new window

Avatar of bje

ASKER

This helps , however,  I am looking at this part,

if [ ``date + %A%l` | egrep -o "Friday13"` ]
        then
         mv $file ${second_dir}

it gives me this error,
 line 185: =: command not found
+ '[' date + %A%l ']'
: line 185: [: +: binary operator expected

Trying to move a file only if it is Friday at 13:00

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial